start

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StartCmd = &cli.Command{
	Name:  "start",
	Usage: "start goplz",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  "detach",
			Value: true,
			Usage: "if true, detach from parent process.",
		},
		&cli.BoolFlag{
			Name:  "detached",
			Value: false,
			Usage: "True means the current process has been detached from parent process. Do not set it manually, it's only used by goplz to detach itself.",
		},
	},
	Action: func(ctx *cli.Context) error {
		verbose = ctx.Bool("verbose")

		fmt.Printf("Starting goplz ...\n")

		cfg := conf.Cfg()
		if _, err := os.Stat(cfg.GoplzPid); !os.IsNotExist(err) {
			b, err := ioutil.ReadFile(cfg.GoplzPid)
			if err != nil {
				panic(err)
			}
			pid, err := strconv.Atoi(string(b))
			if err != nil {
				panic(err)
			}

			p, _ := os.FindProcess(pid)
			if err := p.Signal(syscall.Signal(0)); err == nil {

				fmt.Println("goplz already started, start IDE.")
				startIDE(cfg)
				return nil
			}

			log.Printf("Process with ID %d in file %s does not exist, remove.\n", pid, cfg.GoplzPid)
			os.Remove(cfg.GoplzPid)
		}

		detach := ctx.Bool("detach")
		detached := ctx.Bool("detached")
		if detach && !detached {
			pid, err := detachProcess()
			if err != nil {
				fmt.Println(err)
				os.Exit(2)
			}
			fmt.Printf("goplz is running detached. To stop it, run `goplz stop` or `kill -SIGQUIT %d`.\n", pid)
			return nil
		}

		gopathfs.Init(ctx)
		vfs.Init(ctx)

		mapper := mapping.New(cfg)
		fs := createVirtualFS(cfg, mapper)

		startGopathFS(cfg, detach, fs, mapper)

		return nil
	},
}

StartCmd is for subcommand "start".

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL