Skip to content
Open
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
9 changes: 7 additions & 2 deletions pkg/cmd/clustertriggerbinding/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (

type listOptions struct {
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -78,7 +79,10 @@ or
Err: cmd.OutOrStderr(),
}

if output == "name" && tbs != nil {
switch {
case output == "ndjson":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike other commands in this PR (e.g., pipelinerun, taskrun, customrun) which guard with && prs != nil or similar, this branch passes tbs directly without a nil check. If tbs is nil, runtime.DefaultUnstructuredConverter.ToUnstructured(nil) will panic.
Can we to something like:

case output == "ndjson" && tbs != nil:
    return formatted.PrintNDJSON(stream.Out, tbs, opts.Fields)

return formatted.PrintNDJSON(stream.Out, tbs, opts.Fields)
case output == "name" && tbs != nil:
w := cmd.OutOrStdout()
for _, pr := range tbs.Items {
_, err := fmt.Fprintf(w, "clustertriggerbinding.triggers.tekton.dev/%s\n", pr.Name)
Expand All @@ -87,7 +91,7 @@ or
}
}
return nil
} else if output != "" {
case output != "":
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -105,6 +109,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)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/customrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ListOptions struct {
Reverse bool
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -92,7 +93,10 @@ func listCommand(p cli.Params) *cobra.Command {
if err != nil {
return fmt.Errorf("output option not set properly: %v", err)
}
if output == "name" && crs != nil {
switch {
case output == "ndjson" && crs != nil:
return formatted.PrintNDJSON(cmd.OutOrStdout(), crs, opts.Fields)
case output == "name" && crs != nil:
w := cmd.OutOrStdout()
for _, tr := range crs.Items {
_, err := fmt.Fprintf(w, "customrun.tekton.dev/%s\n", tr.Name)
Expand All @@ -101,7 +105,7 @@ func listCommand(p cli.Params) *cobra.Command {
}
}
return nil
} else if output != "" && crs != nil {
case output != "" && crs != nil:
p, err := f.ToPrinter()
if err != nil {
return err
Expand Down Expand Up @@ -133,6 +137,7 @@ func listCommand(p cli.Params) *cobra.Command {
c.Flags().BoolVarP(&opts.Reverse, "reverse", "", opts.Reverse, "list CustomRuns in reverse order")
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list CustomRuns from all namespaces")
c.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/eventlistener/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
type listOptions struct {
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -88,7 +89,9 @@ or
Err: cmd.OutOrStderr(),
}

if output != "" {
if output == "ndjson" {
return formatted.PrintNDJSON(stream.Out, els, opts.Fields)
} else if output != "" {
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -106,6 +109,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)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/cmd/pipeline/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ NAME AGE LAST RUN STARTED DURATION STATUS
type ListOptions struct {
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -91,7 +92,17 @@ func listCommand(p cli.Params) *cobra.Command {
ns = ""
}

if output != "" {
if output == "ndjson" {
var pl *v1.PipelineList
if err := actions.ListV1(pipelineGroupResource, cs, metav1.ListOptions{}, ns, &pl); err != nil {
scope := fmt.Sprintf("namespace %q", ns)
if ns == "" {
Comment on lines +95 to +99
scope = "all namespaces"
}
return fmt.Errorf("failed to list Pipelines from %s: %w", scope, err)
}
return formatted.PrintNDJSON(cmd.OutOrStdout(), pl, opts.Fields)
} else if output != "" {
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -108,6 +119,7 @@ func listCommand(p cli.Params) *cobra.Command {
f.AddFlags(c)
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list Pipelines from all namespaces")
c.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user passes --fields metadata.name without --output ndjson (or with --output json), the flag is silently ignored. This could lead to confusion. Can we add validation in the RunE function:

if len(opts.Fields) > 0 && output != "ndjson" {
    return fmt.Errorf("--fields is only supported with --output ndjson")
}

This should apply to all list commands.


return c
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/pipelinerun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ListOptions struct {
Reverse bool
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -101,7 +102,10 @@ List all PipelineRuns in a namespace 'foo':
return fmt.Errorf("output option not set properly: %v", err)
}

if output == "name" && prs != nil {
switch {
case output == "ndjson" && prs != nil:
return formatted.PrintNDJSON(cmd.OutOrStdout(), prs, opts.Fields)
case output == "name" && prs != nil:
w := cmd.OutOrStdout()
for _, pr := range prs.Items {
_, err := fmt.Fprintf(w, "pipelinerun.tekton.dev/%s\n", pr.Name)
Expand All @@ -110,7 +114,7 @@ List all PipelineRuns in a namespace 'foo':
}
}
return nil
} else if output != "" && prs != nil {
case output != "" && prs != nil:
p, err := f.ToPrinter()
if err != nil {
return err
Expand Down Expand Up @@ -139,6 +143,7 @@ List all PipelineRuns in a namespace 'foo':
c.Flags().BoolVarP(&opts.Reverse, "reverse", "", opts.Reverse, "list PipelineRuns in reverse order")
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list PipelineRuns from all namespaces")
c.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/cmd/task/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ NAME DESCRIPTION AGE
type ListOptions struct {
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -80,7 +81,17 @@ func listCommand(p cli.Params) *cobra.Command {
ns = ""
}

if output != "" {
if output == "ndjson" {
var tl *v1.TaskList
if err := actions.ListV1(taskGroupResource, cs, metav1.ListOptions{}, ns, &tl); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as above — this makes a second API call instead of reusing the already-fetched list. Can we align with the approach used in the other commands.

scope := fmt.Sprintf("namespace %q", ns)
if ns == "" {
scope = "all namespaces"
}
return fmt.Errorf("failed to list Tasks from %s: %w", scope, err)
}
return formatted.PrintNDJSON(cmd.OutOrStdout(), tl, opts.Fields)
} else if output != "" {
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -97,6 +108,7 @@ func listCommand(p cli.Params) *cobra.Command {
f.AddFlags(c)
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list Tasks from all namespaces")
c.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")

return c
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/taskrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ListOptions struct {
Reverse bool
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -102,7 +103,10 @@ List all TaskRuns of Task 'foo' in namespace 'bar':
if err != nil {
return fmt.Errorf("output option not set properly: %v", err)
}
if output == "name" && trs != nil {
switch {
case output == "ndjson" && trs != nil:
return formatted.PrintNDJSON(cmd.OutOrStdout(), trs, opts.Fields)
case output == "name" && trs != nil:
w := cmd.OutOrStdout()
for _, tr := range trs.Items {
_, err := fmt.Fprintf(w, "taskrun.tekton.dev/%s\n", tr.Name)
Expand All @@ -111,7 +115,7 @@ List all TaskRuns of Task 'foo' in namespace 'bar':
}
}
return nil
} else if output != "" && trs != nil {
case output != "" && trs != nil:
p, err := f.ToPrinter()
if err != nil {
return err
Expand Down Expand Up @@ -143,6 +147,7 @@ List all TaskRuns of Task 'foo' in namespace 'bar':
c.Flags().BoolVarP(&opts.Reverse, "reverse", "", opts.Reverse, "list TaskRuns in reverse order")
c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list TaskRuns from all namespaces")
c.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/triggerbinding/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
type listOptions struct {
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -87,7 +88,10 @@ or
Err: cmd.OutOrStderr(),
}

if output == "name" && tbs != nil {
switch {
case output == "ndjson":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also guard against tbs being nil similar to clustertriggerbinding

return formatted.PrintNDJSON(stream.Out, tbs, opts.Fields)
case output == "name" && tbs != nil:
w := cmd.OutOrStdout()
for _, pr := range tbs.Items {
_, err := fmt.Fprintf(w, "triggerbinding.triggers.tekton.dev/%s\n", pr.Name)
Expand All @@ -96,7 +100,7 @@ or
}
}
return nil
} else if output != "" {
case output != "":
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -115,6 +119,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)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/triggertemplate/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
type ListOptions struct {
AllNamespaces bool
NoHeaders bool
Fields []string
}

func listCommand(p cli.Params) *cobra.Command {
Expand Down Expand Up @@ -85,7 +86,9 @@ or
Err: cmd.OutOrStderr(),
}

if output != "" {
if output == "ndjson" {
return formatted.PrintNDJSON(stream.Out, tts, opts.Fields)
} else if output != "" {
p, err := f.ToPrinter()
if err != nil {
return err
Expand All @@ -105,6 +108,7 @@ or

c.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list TriggerTemplates 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)")
c.Flags().StringSliceVar(&opts.Fields, "fields", opts.Fields, "Comma-separated list of fields to include in output (e.g. metadata.name,status.startTime); only used with --output ndjson")
return c
}

Expand Down
Loading
Loading