Skip to content

Commit

Permalink
fix(cli): Check mutual exclusivity for argo CLI flags (#3493)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrytangyuan committed Jul 17, 2020
1 parent 7d45ff7 commit 19e700a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cmd/argo/commands/list.go
Expand Up @@ -65,9 +65,9 @@ func NewListCommand() *cobra.Command {
command.Flags().StringVar(&listArgs.prefix, "prefix", "", "Filter workflows by prefix")
command.Flags().StringVar(&listArgs.finishedAfter, "older", "", "List completed workflows finished before the specified duration (e.g. 10m, 3h, 1d)")
command.Flags().StringSliceVar(&listArgs.status, "status", []string{}, "Filter by status (comma separated)")
command.Flags().BoolVar(&listArgs.completed, "completed", false, "Show only completed workflows")
command.Flags().BoolVar(&listArgs.running, "running", false, "Show only running workflows")
command.Flags().BoolVar(&listArgs.resubmitted, "resubmitted", false, "Show only resubmitted workflows")
command.Flags().BoolVar(&listArgs.completed, "completed", false, "Show completed workflows. Mutually exclusive with --running.")
command.Flags().BoolVar(&listArgs.running, "running", false, "Show running workflows. Mutually exclusive with --completed.")
command.Flags().BoolVar(&listArgs.resubmitted, "resubmitted", false, "Show resubmitted workflows")
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
command.Flags().StringVar(&listArgs.createdSince, "since", "", "Show only workflows created after than a relative duration")
command.Flags().Int64VarP(&listArgs.chunkSize, "chunk-size", "", 0, "Return large lists in chunks rather than all at once. Pass 0 to disable.")
Expand All @@ -89,6 +89,9 @@ func listWorkflows(ctx context.Context, serviceClient workflowpkg.WorkflowServic
labelSelector = labelSelector.Add(*req)
}
}
if flags.completed && flags.running {
log.Fatal("--completed and --running cannot be used together")
}
if flags.completed {
req, _ := labels.NewRequirement(common.LabelKeyCompleted, selection.Equals, []string{"true"})
labelSelector = labelSelector.Add(*req)
Expand Down
5 changes: 5 additions & 0 deletions cmd/argo/commands/logs.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"log"
"os"
"time"

Expand Down Expand Up @@ -67,6 +68,10 @@ func NewLogsCommand() *cobra.Command {
os.Exit(1)
}

if since > 0 && sinceTime != "" {
log.Fatal("--since-time and --since cannot be used together")
}

if since > 0 {
logOptions.SinceSeconds = pointer.Int64Ptr(int64(since.Seconds()))
}
Expand Down
6 changes: 3 additions & 3 deletions docs/cli/argo_list.md
Expand Up @@ -15,15 +15,15 @@ argo list [flags]
```
--all-namespaces Show workflows from all namespaces
--chunk-size int Return large lists in chunks rather than all at once. Pass 0 to disable.
--completed Show only completed workflows
--completed Show completed workflows. Mutually exclusive with --running.
--field-selector string Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selectorkey1=value1,key2=value2). The server only supports a limited number of field queries per type.
-h, --help help for list
--no-headers Don't print headers (default print headers).
--older string List completed workflows finished before the specified duration (e.g. 10m, 3h, 1d)
-o, --output string Output format. One of: wide|name
--prefix string Filter workflows by prefix
--resubmitted Show only resubmitted workflows
--running Show only running workflows
--resubmitted Show resubmitted workflows
--running Show running workflows. Mutually exclusive with --completed.
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
--since string Show only workflows created after than a relative duration
--status strings Filter by status (comma separated)
Expand Down

0 comments on commit 19e700a

Please sign in to comment.