Skip to content

Commit

Permalink
Fix follow mode for interactive pipeline logs
Browse files Browse the repository at this point in the history
Follow mode working for interactive pipeline logs command
Minor code refactor
Adds args validation remove verify

Signed-off-by: Pradeep Kumar <[email protected]>
  • Loading branch information
pradeepitm12 authored and vdemeester committed Aug 8, 2019
1 parent 061fd6a commit 4b04b4d
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions pkg/cmd/pipeline/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ type logOptions struct {
runName string
}

func nameArg(args []string, p cli.Params) error {
if len(args) == 1 {
c, err := p.Clients()
if err != nil {
return err
}
name, ns := args[0], p.Namespace()
if _, err = c.Tekton.TektonV1alpha1().Pipelines(ns).Get(name, metav1.GetOptions{}); err != nil {
return err
}
}
return nil
}

func logCommand(p cli.Params) *cobra.Command {
opts := &logOptions{params: p,
askOpts: func(opt *survey.AskOptions) error {
Expand Down Expand Up @@ -72,6 +86,9 @@ func logCommand(p cli.Params) *cobra.Command {
Short: "Show pipeline logs",
Example: eg,
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
return nameArg(args, p)
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.stream = &cli.Stream{
Out: cmd.OutOrStdout(),
Expand Down Expand Up @@ -100,6 +117,8 @@ func (opts *logOptions) run(args []string) error {
PipelineRunName: opts.runName,
Stream: opts.stream,
Params: opts.params,
Follow: opts.follow,
AllSteps: opts.allSteps,
}

return runLogOpts.Run()
Expand All @@ -117,10 +136,6 @@ func (opts *logOptions) init(args []string) error {

case 1: // pipeline name provided
opts.pipelineName = args[0]
err := verify(opts.pipelineName, opts.params)
if err != nil {
return err
}
if opts.last {
return opts.initLastRunName()
}
Expand All @@ -142,7 +157,7 @@ func (opts *logOptions) getAllInputs() error {
return err
}

if len(ps) < 1 {
if len(ps) == 0 {
fmt.Fprintln(opts.stream.Err, "No pipelines found in namespace:", opts.params.Namespace())
return nil
}
Expand Down Expand Up @@ -171,7 +186,7 @@ func (opts *logOptions) askRunName() error {
if err != nil {
return err
}
if len(prs) < 1 {
if len(prs) == 0 {
fmt.Fprintln(opts.stream.Err, "No pipelineruns found for pipeline:", opts.pipelineName)
return nil
}
Expand All @@ -194,19 +209,6 @@ func (opts *logOptions) askRunName() error {
return nil
}

func verify(pname string, params cli.Params) error {
cs, err := params.Clients()
if err != nil {
return err
}

tkn := cs.Tekton.TektonV1alpha1()
if _, err = tkn.Pipelines(params.Namespace()).Get(pname, metav1.GetOptions{}); err != nil {
return err
}
return nil
}

func (opts *logOptions) initLastRunName() error {
cs, err := opts.params.Clients()
if err != nil {
Expand Down

0 comments on commit 4b04b4d

Please sign in to comment.