Skip to content
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_eventlistener_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ or
-A, --all-namespaces list EventListeners 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].
```
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/tkn-eventlistener-list.1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Lists EventListeners 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
10 changes: 7 additions & 3 deletions pkg/cmd/eventlistener/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (

type listOptions struct {
AllNamespaces bool
NoHeaders bool
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -94,7 +95,7 @@ or
return printer.PrintObject(stream.Out, els, f)
}

if err = printFormatted(stream, els, p, opts.AllNamespaces); err != nil {
if err = printFormatted(stream, els, p, opts.AllNamespaces, opts.NoHeaders); err != nil {
return errors.New(`failed to print EventListeners`)
}
return nil
Expand All @@ -103,6 +104,7 @@ or

f.AddFlags(c)
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list EventListeners 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
}

Expand All @@ -123,7 +125,7 @@ func list(client versioned.Interface, namespace string) (*v1alpha1.EventListener
return els, nil
}

func printFormatted(s *cli.Stream, els *v1alpha1.EventListenerList, p cli.Params, allNamespaces bool) error {
func printFormatted(s *cli.Stream, els *v1alpha1.EventListenerList, p cli.Params, allNamespaces bool, noHeaders bool) error {
if len(els.Items) == 0 {
fmt.Fprintln(s.Err, emptyMsg)
return nil
Expand All @@ -135,7 +137,9 @@ func printFormatted(s *cli.Stream, els *v1alpha1.EventListenerList, p cli.Params
}

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, headers)
if !noHeaders {
fmt.Fprintln(w, headers)
}
for _, el := range els.Items {

status := corev1.ConditionStatus("---")
Expand Down
12 changes: 12 additions & 0 deletions pkg/cmd/eventlistener/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ func TestListEventListener(t *testing.T) {
args: []string{"list", "--all-namespaces"},
wantError: false,
},
{
name: "List EventListeners without headers",
command: command(t, els, now, ns),
args: []string{"list", "--no-headers"},
wantError: false,
},
{
name: "List EventListeners from all namespaces without headers",
command: command(t, els, now, ns),
args: []string{"list", "--no-headers", "--all-namespaces"},
wantError: false,
},
}

for _, td := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bar tb0 2 minutes ago http://tb0-listener.default.svc.cluster.local True
foo tb1 2 minutes ago http://tb1-listener.default.svc.cluster.local True
foo tb2 30 seconds ago http://tb2-listener.default.svc.cluster.local True
foo tb3 1 week ago http://tb3-listener.default.svc.cluster.local True
foo tb4 --- --- ---
foo tb5 10 seconds ago --- False
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tb0 2 minutes ago http://tb0-listener.default.svc.cluster.local True
tb1 2 minutes ago http://tb1-listener.default.svc.cluster.local True
tb2 30 seconds ago http://tb2-listener.default.svc.cluster.local True
tb3 1 week ago http://tb3-listener.default.svc.cluster.local True
tb4 --- --- ---
tb5 10 seconds ago --- False