-
Notifications
You must be signed in to change notification settings - Fork 6
/
unsuspend.go
48 lines (43 loc) · 1.22 KB
/
unsuspend.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
36
37
38
39
40
41
42
43
44
45
46
47
48
package cron
import (
"errors"
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
)
func unsuspendCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "unsuspend cronjob [flags]",
Short: "Unsuspend a cron job",
Long: `Unsuspends the specified cron job.
If the cron job is not suspended, does nothing.`,
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, args)
if err != nil {
return err
}
all, err := c.ListCronJobsOverContexts(ctxs, namespace, options)
if err != nil {
return err
}
if len(all) == 0 {
return errors.New("no cronjobs found")
} else if len(all) > 1 {
return errors.New("too many cronjobs match the criteria")
}
success, err := c.SetCronJobSuspend(all[0].Context, all[0].Namespace, all[0].Name, false)
if err != nil {
return err
}
if success {
cmd.Println("Successfully unsuspended cron job", args[0])
} else {
cmd.Printf("Cron job \"%s\" was already unsuspended\n", args[0])
}
return err
},
}
}