Example #1
0
func AddAction(ctx *cli.Context, client pb.GoSuvClient) {
	name := ctx.String("name")
	if name == "" {
		name = filepath.Base(ctx.Args()[0])
	}

	dir, _ := os.Getwd()

	if len(ctx.Args()) < 1 {
		log.Fatal("need at least one args")
	}
	cmdName := ctx.Args().First()
	cmdPath, err := exec.LookPath(cmdName)
	if err != nil {
		log.Fatal(err)
	}

	req := new(pb.ProgramInfo)
	req.Name = ctx.String("name")
	req.Directory = dir
	req.Command = append([]string{cmdPath}, ctx.Args().Tail()...)
	req.Environ = ctx.StringSlice("env")

	res, err := client.Create(context.Background(), req)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Message)
}
Example #2
0
func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
	fmt.Printf("Client: %s\n", GOSUV_VERSION)
	res, err := client.Version(context.Background(), &pb.NopRequest{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Server: %s\n", res.Message)
}
Example #3
0
func StatusAction(client pb.GoSuvClient) {
	res, err := client.Status(context.Background(), &pb.NopRequest{})
	if err != nil {
		log.Fatal(err)
	}
	for _, ps := range res.GetPrograms() {
		fmt.Printf("%-10s\t%-8s\t%s\n", ps.Name, ps.Status, ps.Extra)
	}
}