Skip to content

Commit

Permalink
feat(cli): Add a flag status to delete cmd like list cmd of argo cli (#…
Browse files Browse the repository at this point in the history
…11577)

Signed-off-by: spencercjh <spencercjh@gmail.com>
  • Loading branch information
spencercjh committed Aug 17, 2023
1 parent 1e573d3 commit 27ffa83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions cmd/argo/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewDeleteCommand() *cobra.Command {
force bool
)
command := &cobra.Command{
Use: "delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] ]",
Use: "delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] [--status STATUS] ]",
Short: "delete workflows",
Example: `# Delete a workflow:
Expand All @@ -36,7 +36,10 @@ func NewDeleteCommand() *cobra.Command {
argo delete @latest
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 && !(all || allNamespaces || flags.completed || flags.resubmitted || flags.prefix != "" || flags.labels != "" || flags.fields != "" || flags.finishedAfter != "") {
hasFilterFlag := all || allNamespaces || flags.completed || flags.resubmitted || flags.prefix != "" ||
flags.labels != "" || flags.fields != "" || flags.finishedAfter != "" || len(flags.status) > 0

if len(args) == 0 && !hasFilterFlag {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
Expand All @@ -52,7 +55,7 @@ func NewDeleteCommand() *cobra.Command {
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: flags.namespace},
})
}
if all || flags.completed || flags.resubmitted || flags.prefix != "" || flags.labels != "" || flags.fields != "" || flags.finishedAfter != "" {
if hasFilterFlag {
listed, err := listWorkflows(ctx, serviceClient, flags)
errors.CheckError(err)
workflows = append(workflows, listed...)
Expand Down Expand Up @@ -85,9 +88,10 @@ func NewDeleteCommand() *cobra.Command {
command.Flags().BoolVar(&flags.completed, "completed", false, "Delete completed workflows")
command.Flags().BoolVar(&flags.resubmitted, "resubmitted", false, "Delete resubmitted workflows")
command.Flags().StringVar(&flags.prefix, "prefix", "", "Delete workflows by prefix")
command.Flags().StringVar(&flags.finishedAfter, "older", "", "Delete completed workflows finished before the specified duration (e.g. 10m, 3h, 1d)")
command.Flags().StringVarP(&flags.labels, "selector", "l", "", "Selector (label query) to filter on, not including uninitialized ones, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
command.Flags().StringVar(&flags.fields, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.")
command.Flags().StringVar(&flags.finishedAfter, "older", "", "Delete completed workflows finished before the specified duration (e.g. 10m, 3h, 1d)")
command.Flags().StringSliceVar(&flags.status, "status", []string{}, "Delete by status (comma separated)")
command.Flags().Int64VarP(&flags.chunkSize, "query-chunk-size", "", 0, "Run the list query in chunks (deletes will still be executed individually)")
command.Flags().BoolVar(&dryRun, "dry-run", false, "Do not delete the workflow, only print what would happen")
command.Flags().BoolVar(&force, "force", false, "Force delete workflows by removing finalizers")
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/argo_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
delete workflows

```
argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] ] [flags]
argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] [--status STATUS] ] [flags]
```

### Examples
Expand Down Expand Up @@ -34,6 +34,7 @@ argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmit
--query-chunk-size int Run the list query in chunks (deletes will still be executed individually)
--resubmitted Delete resubmitted workflows
-l, --selector string Selector (label query) to filter on, not including uninitialized ones, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
--status strings Delete by status (comma separated)
```

### Options inherited from parent commands
Expand Down

0 comments on commit 27ffa83

Please sign in to comment.