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 --output for TriggerBinding and TaskRuns #681

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
12 changes: 10 additions & 2 deletions pkg/cmd/taskrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/taskrun/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion pkg/cmd/triggerbinding/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/triggerbinding/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
triggerbinding.tekton.dev/tb1
triggerbinding.tekton.dev/tb2
triggerbinding.tekton.dev/tb3
triggerbinding.tekton.dev/tb4