Пример #1
0
func Server(c *cli.Context) string {
	val := c.String("server")
	if val == "" {
		val = c.GlobalString("server")
	}
	return val
}
Пример #2
0
func cmdCronDelete(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Die(err)
	}

	server := stdcli.Server(c)

	id, err := strconv.Atoi(c.Args().First())

	if err != nil {
		stdcli.Die(err)
	}

	path := fmt.Sprintf("/apps/%s/jobs/%d", app, id)

	_, err = client.Request("DELETE", server, path, nil)

	if err != nil {
		stdcli.Die(err)
	}

	fmt.Printf("Deleted #%d\n", id)
}
Пример #3
0
// If user specifies the app's name from command line, then use it;
// otherwise use the current working directory's name
// from https://github.com/convox/cli/blob/0c3efc6892cb9a58aec60bd912e060c602f9ab61/stdcli/stdcli.go#L86
func DirApp(c *cli.Context, wd string) (string, string, error) {
	abs, err := filepath.Abs(wd)

	if err != nil {
		return "", "", err
	}

	app := c.String("app")
	if app == "" {
		app = c.GlobalString("app")
	}

	if app == "" {
		app = path.Base(abs)
	}

	return abs, app, nil
}
Пример #4
0
func cmdCronCreate(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Die(err)
	}

	server := stdcli.Server(c)
	path := fmt.Sprintf("/apps/%s/jobs", app)

	args, err := shellquote.Split(c.Args().First())

	if err != nil {
		stdcli.Die(err)
	}

	if len(args) < 6 {
		stdcli.DieWithUsage(c, fmt.Errorf("argument is not in crontab format: `%s`", c.Args().First()))
	}

	job := stdcli.Job{
		Schedule: strings.Join(args[0:5], " "),
		Command:  strings.Join(args[5:], " "),
		App:      app,
	}

	data, err := json.Marshal(job)

	if err != nil {
		stdcli.Die(err)
	}

	body, err := client.Request("POST", server, path, bytes.NewReader(data))

	if err != nil {
		stdcli.Die(err)
	}

	err = json.Unmarshal(body, &job)

	fmt.Printf("Created #%d\n", job.Id)
	stdcli.PrintJobs(job)
}