From 65b368551fda4890c6955bfb026d5e8fe0066a61 Mon Sep 17 00:00:00 2001 From: Pratik Jagrut <26519653+pratikjagrut@users.noreply.github.com> Date: Tue, 17 Nov 2020 12:36:04 +0530 Subject: [PATCH] Add --no-headers flag to tkn triggerbinding list command Sample output: -------------------------------------- tkn triggerbinding list --no-headers event-binding 23 seconds ago prod-env 1 week ago staging-env 23 seconds ago -------------------------------------- --- docs/cmd/tkn_triggerbinding_list.md | 1 + docs/man/man1/tkn-triggerbinding-list.1 | 4 ++++ pkg/cmd/triggerbinding/list.go | 10 +++++++--- pkg/cmd/triggerbinding/list_test.go | 12 ++++++++++++ ...ndings_from_all_namespaces_without_headers.golden | 5 +++++ ...nding-List_TriggerBindings_without_headers.golden | 5 +++++ 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_from_all_namespaces_without_headers.golden create mode 100644 pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_without_headers.golden diff --git a/docs/cmd/tkn_triggerbinding_list.md b/docs/cmd/tkn_triggerbinding_list.md index 2cbbca6643..368215c55f 100644 --- a/docs/cmd/tkn_triggerbinding_list.md +++ b/docs/cmd/tkn_triggerbinding_list.md @@ -31,6 +31,7 @@ or -A, --all-namespaces list TriggerBindings from all namespaces --allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) -h, --help help for list + --no-headers do not print column headers with output (default print column headers with output) -o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file. --template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. ``` diff --git a/docs/man/man1/tkn-triggerbinding-list.1 b/docs/man/man1/tkn-triggerbinding-list.1 index 12f1c2f361..4e3c7ea98b 100644 --- a/docs/man/man1/tkn-triggerbinding-list.1 +++ b/docs/man/man1/tkn-triggerbinding-list.1 @@ -31,6 +31,10 @@ Lists TriggerBindings in a namespace \fB\-h\fP, \fB\-\-help\fP[=false] help for list +.PP +\fB\-\-no\-headers\fP[=false] + do not print column headers with output (default print column headers with output) + .PP \fB\-o\fP, \fB\-\-output\fP="" Output format. One of: json|yaml|name|go\-template|go\-template\-file|template|templatefile|jsonpath|jsonpath\-file. diff --git a/pkg/cmd/triggerbinding/list.go b/pkg/cmd/triggerbinding/list.go index fe4317fdeb..8713b6308e 100644 --- a/pkg/cmd/triggerbinding/list.go +++ b/pkg/cmd/triggerbinding/list.go @@ -37,6 +37,7 @@ const ( type listOptions struct { AllNamespaces bool + NoHeaders bool } func listCommand(p cli.Params) *cobra.Command { @@ -102,7 +103,7 @@ or return printer.PrintObject(stream.Out, tbs, f) } - if err = printFormatted(stream, tbs, p, opts.AllNamespaces); err != nil { + if err = printFormatted(stream, tbs, p, opts.AllNamespaces, opts.NoHeaders); err != nil { return errors.New("failed to print TriggerBindings") } return nil @@ -112,6 +113,7 @@ or f.AddFlags(c) c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list TriggerBindings from all namespaces") + c.Flags().BoolVar(&opts.NoHeaders, "no-headers", opts.NoHeaders, "do not print column headers with output (default print column headers with output)") return c } @@ -132,7 +134,7 @@ func list(client versioned.Interface, namespace string) (*v1alpha1.TriggerBindin return tbs, nil } -func printFormatted(s *cli.Stream, tbs *v1alpha1.TriggerBindingList, p cli.Params, allNamespaces bool) error { +func printFormatted(s *cli.Stream, tbs *v1alpha1.TriggerBindingList, p cli.Params, allNamespaces bool, noHeaders bool) error { if len(tbs.Items) == 0 { fmt.Fprintln(s.Err, emptyMsg) return nil @@ -144,7 +146,9 @@ func printFormatted(s *cli.Stream, tbs *v1alpha1.TriggerBindingList, p cli.Param } w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - fmt.Fprintln(w, headers) + if !noHeaders { + fmt.Fprintln(w, headers) + } for _, tb := range tbs.Items { if allNamespaces { fmt.Fprintf(w, "%s\t%s\t%s\n", diff --git a/pkg/cmd/triggerbinding/list_test.go b/pkg/cmd/triggerbinding/list_test.go index 5b828af187..8dea31c11c 100644 --- a/pkg/cmd/triggerbinding/list_test.go +++ b/pkg/cmd/triggerbinding/list_test.go @@ -103,6 +103,18 @@ func TestListTriggerBinding(t *testing.T) { args: []string{"list", "--all-namespaces"}, wantError: false, }, + { + name: "List TriggerBindings without headers", + command: command(t, tbs, now, ns), + args: []string{"list", "--no-headers"}, + wantError: false, + }, + { + name: "List TriggerBindings from all namespaces without headers", + command: command(t, tbs, now, ns), + args: []string{"list", "--no-headers", "--all-namespaces"}, + wantError: false, + }, } for _, td := range tests { diff --git a/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_from_all_namespaces_without_headers.golden b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_from_all_namespaces_without_headers.golden new file mode 100644 index 0000000000..2e51e53881 --- /dev/null +++ b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_from_all_namespaces_without_headers.golden @@ -0,0 +1,5 @@ +bar tb0 2 minutes ago +foo tb1 2 minutes ago +foo tb2 30 seconds ago +foo tb3 1 week ago +foo tb4 --- diff --git a/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_without_headers.golden b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_without_headers.golden new file mode 100644 index 0000000000..b64e0f461c --- /dev/null +++ b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-List_TriggerBindings_without_headers.golden @@ -0,0 +1,5 @@ +tb0 2 minutes ago +tb1 2 minutes ago +tb2 30 seconds ago +tb3 1 week ago +tb4 ---