forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
44 lines (39 loc) · 1.2 KB
/
delete.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
package cron
import (
"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
"github.com/simster7/argo/v2/cmd/argo/commands/client"
cronworkflowpkg "github.com/simster7/argo/v2/pkg/apiclient/cronworkflow"
)
// NewDeleteCommand returns a new instance of an `argo delete` command
func NewDeleteCommand() *cobra.Command {
var (
all bool
)
var command = &cobra.Command{
Use: "delete [CRON_WORKFLOW... | --all]",
Short: "delete a cron workflow",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewCronWorkflowServiceClient()
if all {
cronWfList, err := serviceClient.ListCronWorkflows(ctx, &cronworkflowpkg.ListCronWorkflowsRequest{
Namespace: client.Namespace(),
})
errors.CheckError(err)
for _, cronWf := range cronWfList.Items {
args = append(args, cronWf.Name)
}
}
for _, name := range args {
_, err := serviceClient.DeleteCronWorkflow(ctx, &cronworkflowpkg.DeleteCronWorkflowRequest{
Name: name,
Namespace: client.Namespace(),
})
errors.CheckError(err)
}
},
}
command.Flags().BoolVar(&all, "all", false, "Delete all workflow templates")
return command
}