-
Notifications
You must be signed in to change notification settings - Fork 6
/
exec.go
35 lines (30 loc) · 1005 Bytes
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cron
import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
)
func execCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "exec cronjob [flags]",
Short: "Executes a job now",
Long: `Executes the specified job or the selected job if none.
Namespace and context flags can be set to help find the right cron job.
If multiple cron job are found, only the first one will be executed.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctxs, _ := cmd.Flags().GetStringSlice("context")
namespace, _ := cmd.Flags().GetString("namespace")
options, err := parsing.ListOptions(cmd, nil)
if err != nil {
return err
}
job, err := c.RunCronJob(ctxs, namespace, args[0], options)
if err != nil {
return err
}
cmd.Printf("Successfully started job \"%s\" in context \"%s\" and namespace \"%s\"\n", job.Name, job.Context, job.Namespace)
return nil
},
}
}