Skip to content

Commit 8bebeb6

Browse files
committed
Add --last to tkn pac logs
And make all the help messages uses it instead of tkn pr directly Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent 9e010b7 commit 8bebeb6

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

docs/content/docs/guide/running.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ You can follow the execution of your pipeline with the
4343
[tkn](https://github.com/tektoncd/cli) cli :
4444

4545
```console
46-
tkn pr logs -n my-pipeline-ci -Lf
46+
tkn pac logs -n my-pipeline-ci -L
4747
```
4848

4949
If you need to show another pipelinerun than the last one you

pkg/cmd/tknpac/logs/logs.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ tkn pac logs will get the logs of a PipelineRun belonging to a Repository.
3535
the PipelineRun needs to exist on the kubernetes cluster to be able to display the logs.`
3636

3737
const (
38-
namespaceFlag = "namespace"
39-
limitFlag = "limit"
40-
tknPathFlag = "tkn-path"
41-
defaultLimit = -1
42-
openWebBrowserFlag = "web"
38+
namespaceFlag = "namespace"
39+
limitFlag = "limit"
40+
tknPathFlag = "tkn-path"
41+
defaultLimit = -1
42+
openWebBrowserFlag = "web"
43+
useLastPipelineRunFlag = "last"
4344
)
4445

4546
type logOption struct {
@@ -51,6 +52,7 @@ type logOption struct {
5152
tknPath string
5253
limit int
5354
webBrowser bool
55+
useLastPR bool
5456
}
5557

5658
func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
@@ -92,6 +94,11 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
9294
return err
9395
}
9496

97+
useLastPR, err := cmd.Flags().GetBool(useLastPipelineRunFlag)
98+
if err != nil {
99+
return err
100+
}
101+
95102
tknPath, err := cmd.Flags().GetString(tknPathFlag)
96103
if err != nil {
97104
return err
@@ -115,6 +122,7 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
115122
limit: limit,
116123
webBrowser: webBrowser,
117124
tknPath: tknPath,
125+
useLastPR: useLastPR,
118126
}
119127
return log(ctx, lopts)
120128
},
@@ -134,6 +142,9 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
134142
cmd.Flags().BoolP(
135143
openWebBrowserFlag, "w", false, "Open Web browser to detected console instead of using tkn")
136144

145+
cmd.Flags().BoolP(
146+
useLastPipelineRunFlag, "L", false, "show logs of the last PipelineRun")
147+
137148
cmd.Flags().IntP(
138149
limitFlag, "", defaultLimit, "Limit the number of PipelineRun to show (-1 is unlimited)")
139150

@@ -213,7 +224,7 @@ func log(ctx context.Context, lo *logOption) error {
213224
return fmt.Errorf("cannot detect pipelineruns belonging to repository: %s", repository.GetName())
214225
}
215226
var replyString string
216-
if len(allprs) == 1 {
227+
if lo.useLastPR || len(allprs) == 1 {
217228
replyString = allprs[0]
218229
} else {
219230
if err := prompt.SurveyAskOne(&survey.Select{

pkg/cmd/tknpac/logs/logs_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestLogs(t *testing.T) {
3535
currentNamespace string
3636
shift int
3737
pruns []*tektonv1beta1.PipelineRun
38+
useLastPR bool
3839
}{
3940
{
4041
name: "good/show logs",
@@ -48,6 +49,21 @@ func TestLogs(t *testing.T) {
4849
}, 30),
4950
},
5051
},
52+
{
53+
name: "good/show logs",
54+
wantErr: false,
55+
repoName: "test",
56+
currentNamespace: ns,
57+
useLastPR: true,
58+
pruns: []*tektonv1beta1.PipelineRun{
59+
tektontest.MakePRCompletion(cw, "test-pipeline", ns, completed, map[string]string{
60+
keys.Repository: "test",
61+
}, 30),
62+
tektontest.MakePRCompletion(cw, "test-pipeline2", ns, completed, map[string]string{
63+
keys.Repository: "test",
64+
}, 30),
65+
},
66+
},
5167
{
5268
name: "bad/shift",
5369
wantErr: true,
@@ -116,6 +132,7 @@ func TestLogs(t *testing.T) {
116132
limit: 1,
117133
tknPath: tknPath,
118134
ioStreams: io,
135+
useLastPR: tt.useLastPR,
119136
}
120137

121138
err = log(ctx, lopts)

pkg/pipelineascode/pipelineascode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
2727
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
2828
the command line with :
29-
<br><code>tkn pr logs -f -n %s %s</code>`
29+
<br><code>tkn pac logs -L -n %s %s</code>`
3030
queuingPipelineRunText = `PipelineRun <b>%s</b> has been queued Queuing in namespace
3131
<b>%s</b><br><br>`
3232
)

pkg/reconciler/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
const startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
3232
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
3333
the command line with :
34-
<br><code>tkn pr logs -f -n %s %s</code>`
34+
<br><code>tkn pac logs -L -n %s %s</code>`
3535

3636
type Reconciler struct {
3737
run *params.Run

0 commit comments

Comments
 (0)