Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-headers flag to tkn clustertriggerbinding list command #1243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cmd/tkn_clustertriggerbinding_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ or
```
--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].
```
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/tkn-clustertriggerbinding-list.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Lists ClusterTriggerBindings 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.
Expand Down
15 changes: 11 additions & 4 deletions pkg/cmd/clustertriggerbinding/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ const (
emptyMsg = "No ClusterTriggerBindings found"
)

type listOptions struct {
NoHeaders bool
}

func listCommand(p cli.Params) *cobra.Command {
opts := &listOptions{}
f := cliopts.NewPrintFlags("list")

eg := `List all ClusterTriggerBindings:
Expand Down Expand Up @@ -89,7 +94,7 @@ or
return printer.PrintObject(stream.Out, tbs, f)
}

if err = printFormatted(stream, tbs, p); err != nil {
if err = printFormatted(stream, tbs, p, opts.NoHeaders); err != nil {
return fmt.Errorf("failed to print ClusterTriggerBindings: %v", err)
}
return nil
Expand All @@ -98,7 +103,7 @@ or
}

f.AddFlags(c)

c.Flags().BoolVar(&opts.NoHeaders, "no-headers", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
return c
}

Expand All @@ -119,14 +124,16 @@ func list(client versioned.Interface, namespace string) (*v1alpha1.ClusterTrigge
return tbs, nil
}

func printFormatted(s *cli.Stream, tbs *v1alpha1.ClusterTriggerBindingList, p cli.Params) error {
func printFormatted(s *cli.Stream, tbs *v1alpha1.ClusterTriggerBindingList, p cli.Params, noHeaders bool) error {
if len(tbs.Items) == 0 {
fmt.Fprintln(s.Err, emptyMsg)
return nil
}

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "NAME\tAGE")
if !noHeaders {
fmt.Fprintln(w, "NAME\tAGE")
}
for _, tb := range tbs.Items {
fmt.Fprintf(w, "%s\t%s\n",
tb.Name,
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/clustertriggerbinding/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func TestListClusterTriggerBinding(t *testing.T) {
args: []string{"list", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}"},
wantError: false,
},
{
name: "List ClusterTriggerBindings without headers",
command: command(t, ctbs, now),
args: []string{"list", "--no-headers"},
wantError: false,
},
}

for _, td := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ctb1 2 minutes ago
ctb2 30 seconds ago
ctb3 1 week ago
ctb4 ---