diff --git a/pkg/shp/cmd/build/upload.go b/pkg/shp/cmd/build/upload.go index 7abe3dd3e..597518ffc 100644 --- a/pkg/shp/cmd/build/upload.go +++ b/pkg/shp/cmd/build/upload.go @@ -2,7 +2,6 @@ package build // nolint:revive import ( "fmt" - "log" "os" "path" "time" @@ -38,8 +37,9 @@ type UploadCommand struct { sourceBundleImage string // image to be used as the source bundle - pw *reactor.PodWatcher // pod-watcher instance - follower *follower.Follower // follower instance + ioStreams *genericclioptions.IOStreams // io streams for user-facing output + pw *reactor.PodWatcher // pod-watcher instance + follower *follower.Follower // follower instance } const ( @@ -186,7 +186,7 @@ func (u *UploadCommand) createBuildRun(p *params.Params) (*buildv1beta1.BuildRun flags.SanitizeBuildRunSpec(&br.Spec) ns := p.Namespace() - log.Printf("Creating a BuildRun for '%s/%s' Build...", ns, u.buildRefName) + fmt.Fprintf(u.ioStreams.Out, "Creating a BuildRun for '%s/%s' Build...\n", ns, u.buildRefName) clientset, err := p.ShipwrightClientSet() if err != nil { return nil, err @@ -197,7 +197,7 @@ func (u *UploadCommand) createBuildRun(p *params.Params) (*buildv1beta1.BuildRun if err != nil { return nil, err } - log.Printf("BuildRun '%s' created!", br.GetName()) + fmt.Fprintf(u.ioStreams.Out, "BuildRun '%s' created!\n", br.GetName()) return br, nil } @@ -207,7 +207,7 @@ func (u *UploadCommand) performDataStreaming(target *streamer.Target) error { return nil } - fmt.Fprintf(os.Stdout, "Streaming %q to the Build POD %q ...\n", u.sourceDir, target.Pod) + fmt.Fprintf(u.ioStreams.Out, "Streaming %q to the Build POD %q ...\n", u.sourceDir, target.Pod) // creates an in-memory tarball with source directory data, and ready to start data streaming tarball, err := streamer.NewTar(u.sourceDir) if err != nil { @@ -280,6 +280,7 @@ func (u *UploadCommand) onPodModifiedEventBundling(pod *corev1.Pod) error { // Run executes the primary business logic of this subcommand, by starting to watch over the build // pod status and react accordingly. func (u *UploadCommand) Run(p *params.Params, ioStreams *genericclioptions.IOStreams) error { + u.ioStreams = ioStreams // creating a BuildRun with settings for the local source upload br, err := u.createBuildRun(p) if err != nil { diff --git a/pkg/shp/cmd/buildrun/list.go b/pkg/shp/cmd/buildrun/list.go index a1034d71a..0afb153e1 100644 --- a/pkg/shp/cmd/buildrun/list.go +++ b/pkg/shp/cmd/buildrun/list.go @@ -2,7 +2,6 @@ package buildrun import ( "fmt" - "os" "text/tabwriter" "time" @@ -61,7 +60,7 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams // TODO: Support multiple output formats here, not only tabwriter // find out more in kubectl libraries and use them - writer := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0) + writer := tabwriter.NewWriter(io.Out, 0, 8, 2, '\t', 0) columnNames := "NAME\tSTATUS\tAGE" columnTemplate := "%s\t%s\t%s\n" diff --git a/pkg/shp/cmd/buildstrategy/list.go b/pkg/shp/cmd/buildstrategy/list.go index ffeeb44a3..f380579c7 100644 --- a/pkg/shp/cmd/buildstrategy/list.go +++ b/pkg/shp/cmd/buildstrategy/list.go @@ -2,7 +2,6 @@ package buildstrategy import ( "fmt" - "os" "text/tabwriter" "time" @@ -50,7 +49,7 @@ func (c *ListCommand) Validate() error { // Run executes list sub-command logic func (c *ListCommand) Run(p *params.Params, io *genericclioptions.IOStreams) error { - w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0) + w := tabwriter.NewWriter(io.Out, 0, 8, 2, '\t', 0) if !c.noHeader { fmt.Fprintln(w, "NAME\tAGE") } diff --git a/pkg/shp/cmd/clusterbuildstrategy/list.go b/pkg/shp/cmd/clusterbuildstrategy/list.go index 740a99d26..a1e688932 100644 --- a/pkg/shp/cmd/clusterbuildstrategy/list.go +++ b/pkg/shp/cmd/clusterbuildstrategy/list.go @@ -2,7 +2,6 @@ package clusterbuildstrategy import ( "fmt" - "os" "text/tabwriter" "time" @@ -49,7 +48,7 @@ func (c *ListCommand) Validate() error { // Run executes list sub-command logic func (c *ListCommand) Run(p *params.Params, io *genericclioptions.IOStreams) error { - w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0) + w := tabwriter.NewWriter(io.Out, 0, 8, 2, '\t', 0) if !c.noHeader { fmt.Fprintln(w, "NAME\tAGE") } diff --git a/pkg/shp/cmd/root.go b/pkg/shp/cmd/root.go index 0fc189cca..30b4d85e0 100644 --- a/pkg/shp/cmd/root.go +++ b/pkg/shp/cmd/root.go @@ -25,7 +25,7 @@ var rootCmd = &cobra.Command{ func NewCmdSHP(ioStreams *genericclioptions.IOStreams) *cobra.Command { p := params.NewParams() p.AddFlags(rootCmd.PersistentFlags()) - rootCmd.AddCommand(version.Command()) + rootCmd.AddCommand(version.Command(ioStreams)) rootCmd.AddCommand(build.Command(p, ioStreams)) rootCmd.AddCommand(buildrun.Command(p, ioStreams)) rootCmd.AddCommand(buildstrategy.Command(p, ioStreams)) diff --git a/pkg/shp/cmd/version/version.go b/pkg/shp/cmd/version/version.go index f66c8070a..6becd4701 100644 --- a/pkg/shp/cmd/version/version.go +++ b/pkg/shp/cmd/version/version.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericclioptions" ) var version string // Command returns Version subcommand of Shipwright CLI // for retrieving the shp version -func Command() *cobra.Command { +func Command(ioStreams *genericclioptions.IOStreams) *cobra.Command { command := &cobra.Command{ Use: "version", Aliases: []string{"v"}, @@ -23,7 +24,7 @@ func Command() *cobra.Command { version = "development" } - fmt.Printf("version: %s\n", version) + fmt.Fprintf(ioStreams.Out, "version: %s\n", version) }, } return command