Esempio n. 1
0
func (c *Command) edit() error {
	if c.pattern == "" {
		return errors.New("edit [name]")
	}

	agent, err := agents.FindOne(c.pattern)
	if err != nil {
		return err
	}

	if agent != nil {
		editor := os.Getenv("EDITOR")
		if editor == "" {
			return errors.New("EDITOR environment variable is not set")
		}

		cmd := exec.Command("sh", "-c", fmt.Sprintf("%s %s", editor, agent.Fullpath))
		err = cmd.Run()
		if err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 2
0
func (c *Command) show() error {
	if c.pattern == "" {
		return errors.New("show [name]")
	}

	agent, err := agents.FindOne(c.pattern)
	if err != nil {
		return err
	}

	if agent != nil {
		data, err := ioutil.ReadFile(agent.Fullpath)
		if err != nil {
			return err
		}
		fmt.Println(string(data))
	}

	return nil
}
Esempio n. 3
0
func (c *Command) launchctl() error {
	agent, err := agents.FindOne(c.pattern)
	if err != nil {
		return err
	}

	if agent != nil {
		switch c.command {
		case "start":
			fmt.Println("starting", agent.Name)
		case "stop":
			fmt.Println("stopping", agent.Name)
		case "restart":
			c.clone("stop").launchctl()
			c.clone("start").launchctl()
		}

		runCmd("launchctl", c.args(agent.Fullpath)...)
	}

	return nil
}