From 14038a3b3c3dc50508143bbce2c119ac8bff2bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=8D=E7=99=BD?= <251098199@qq.com> Date: Sun, 21 Jul 2024 00:23:51 +0800 Subject: [PATCH] feat(cli): support `-l` flag for `template list`. Fixes #13309 (#13364) Signed-off-by: qingfeng777 <251098199@qq.com> --- cmd/argo/commands/template/list.go | 11 +++++++++++ docs/cli/argo_template_list.md | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/argo/commands/template/list.go b/cmd/argo/commands/template/list.go index a1a2556d06af..166712e650eb 100644 --- a/cmd/argo/commands/template/list.go +++ b/cmd/argo/commands/template/list.go @@ -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" @@ -17,6 +20,7 @@ import ( type listFlags struct { allNamespaces bool // --all-namespaces output string // --output + labels string // --selector } func NewListCommand() *cobra.Command { @@ -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) @@ -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 } diff --git a/docs/cli/argo_template_list.md b/docs/cli/argo_template_list.md index 4f951734eda0..f93b407962a7 100644 --- a/docs/cli/argo_template_list.md +++ b/docs/cli/argo_template_list.md @@ -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