Skip to content

Commit

Permalink
feat(cli): support -l flag for template list. Fixes #13309 (#13364)
Browse files Browse the repository at this point in the history
Signed-off-by: qingfeng777 <[email protected]>
  • Loading branch information
qingfeng777 authored Jul 20, 2024
1 parent ea63031 commit 14038a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions cmd/argo/commands/template/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"os"
"text/tabwriter"

"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

"github.com/argoproj/argo-workflows/v3/cmd/argo/commands/client"
workflowtemplatepkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowtemplate"
Expand All @@ -17,6 +20,7 @@ import (
type listFlags struct {
allNamespaces bool // --all-namespaces
output string // --output
labels string // --selector
}

func NewListCommand() *cobra.Command {
Expand All @@ -34,8 +38,14 @@ func NewListCommand() *cobra.Command {
if listArgs.allNamespaces {
namespace = apiv1.NamespaceAll
}
labelSelector, err := labels.Parse(listArgs.labels)
errors.CheckError(err)

wftmplList, err := serviceClient.ListWorkflowTemplates(ctx, &workflowtemplatepkg.WorkflowTemplateListRequest{
Namespace: namespace,
ListOptions: &metav1.ListOptions{
LabelSelector: labelSelector.String(),
},
})
if err != nil {
log.Fatal(err)
Expand All @@ -54,6 +64,7 @@ func NewListCommand() *cobra.Command {
}
command.Flags().BoolVarP(&listArgs.allNamespaces, "all-namespaces", "A", false, "Show workflows from all namespaces")
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
command.Flags().StringVarP(&listArgs.labels, "selector", "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
return command
}

Expand Down
7 changes: 4 additions & 3 deletions docs/cli/argo_template_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ argo template list [flags]
### Options

```
-A, --all-namespaces Show workflows from all namespaces
-h, --help help for list
-o, --output string Output format. One of: wide|name
-A, --all-namespaces Show workflows from all namespaces
-h, --help help for list
-o, --output string Output format. One of: wide|name
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
```

### Options inherited from parent commands
Expand Down

0 comments on commit 14038a3

Please sign in to comment.