diff --git a/pkg/cmd/taskrun/list.go b/pkg/cmd/taskrun/list.go index bf7fbb606..70459db76 100644 --- a/pkg/cmd/taskrun/list.go +++ b/pkg/cmd/taskrun/list.go @@ -88,8 +88,16 @@ List all TaskRuns of Task 'foo' in namespace 'bar': fmt.Fprint(os.Stderr, "Error: output option not set properly \n") return err } - - if output != "" && trs != nil { + if output == "name" && trs != nil { + w := cmd.OutOrStdout() + for _, tr := range trs.Items { + _, err := fmt.Fprintf(w, "taskrun.tekton.dev/%s\n", tr.Name) + if err != nil { + return err + } + } + return nil + } else if output != "" && trs != nil { return printer.PrintObject(cmd.OutOrStdout(), trs, f) } diff --git a/pkg/cmd/taskrun/list_test.go b/pkg/cmd/taskrun/list_test.go index 7cfa7bf4b..6fc2b8c97 100644 --- a/pkg/cmd/taskrun/list_test.go +++ b/pkg/cmd/taskrun/list_test.go @@ -121,6 +121,12 @@ func TestListTaskRuns(t *testing.T) { args: []string{"list", "bar", "-n", "foo"}, wantError: false, }, + { + name: "by output as name", + command: command(t, trs, now, ns), + args: []string{"list", "-n", "foo", "-o", "name"}, + wantError: false, + }, { name: "all in namespace", command: command(t, trs, now, ns), diff --git a/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden b/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden new file mode 100644 index 000000000..e091c84ed --- /dev/null +++ b/pkg/cmd/taskrun/testdata/TestListTaskRuns-by_output_as_name.golden @@ -0,0 +1,5 @@ +taskrun.tekton.dev/tr0-1 +taskrun.tekton.dev/tr3-1 +taskrun.tekton.dev/tr2-2 +taskrun.tekton.dev/tr1-1 +taskrun.tekton.dev/tr2-1 diff --git a/pkg/cmd/triggerbinding/list.go b/pkg/cmd/triggerbinding/list.go index 71f24ab2d..aecec1435 100644 --- a/pkg/cmd/triggerbinding/list.go +++ b/pkg/cmd/triggerbinding/list.go @@ -80,7 +80,16 @@ or Err: cmd.OutOrStderr(), } - if output != "" { + if output == "name" && tbs != nil { + w := cmd.OutOrStdout() + for _, pr := range tbs.Items { + _, err := fmt.Fprintf(w, "triggerbinding.tekton.dev/%s\n", pr.Name) + if err != nil { + return err + } + } + return nil + } else if output != "" { return printer.PrintObject(stream.Out, tbs, f) } diff --git a/pkg/cmd/triggerbinding/list_test.go b/pkg/cmd/triggerbinding/list_test.go index 5a27ff625..433c4b496 100644 --- a/pkg/cmd/triggerbinding/list_test.go +++ b/pkg/cmd/triggerbinding/list_test.go @@ -79,6 +79,12 @@ func TestListTriggerBinding(t *testing.T) { args: []string{"list", "-n", "foo"}, wantError: false, }, + { + name: "by output as name", + command: command(t, tbs, now, ns), + args: []string{"list", "-n", "foo", "-o", "name"}, + wantError: false, + }, { name: "Multiple TriggerBinding with output format", command: command(t, tbs, now, ns), diff --git a/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-by_output_as_name.golden b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-by_output_as_name.golden new file mode 100644 index 000000000..3ded0e458 --- /dev/null +++ b/pkg/cmd/triggerbinding/testdata/TestListTriggerBinding-by_output_as_name.golden @@ -0,0 +1,4 @@ +triggerbinding.tekton.dev/tb1 +triggerbinding.tekton.dev/tb2 +triggerbinding.tekton.dev/tb3 +triggerbinding.tekton.dev/tb4