diff --git a/cmd/syft/cli/cli.go b/cmd/syft/cli/cli.go index 2c7f44dc3a5..691b366f5df 100644 --- a/cmd/syft/cli/cli.go +++ b/cmd/syft/cli/cli.go @@ -91,5 +91,8 @@ func create(id clio.Identification, out io.Writer) (clio.Application, *cobra.Com cranecmd.NewCmdAuthLogin(id.Name), // syft login uses the same command as crane ) + // explicitly set Cobra output to the real stdout to write things like errors and help + rootCmd.SetOut(out) + return app, rootCmd } diff --git a/cmd/syft/cli/commands/root.go b/cmd/syft/cli/commands/root.go index fb3234b50b9..6c41fe4a2c7 100644 --- a/cmd/syft/cli/commands/root.go +++ b/cmd/syft/cli/commands/root.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/anchore/clio" + "github.com/anchore/syft/cmd/syft/internal/ui" ) func Root(app clio.Application, packagesCmd *cobra.Command) *cobra.Command { @@ -21,6 +22,9 @@ func Root(app clio.Application, packagesCmd *cobra.Command) *cobra.Command { Example: packagesCmd.Example, PreRunE: applicationUpdateCheck(id, &opts.UpdateCheck), RunE: func(cmd *cobra.Command, args []string) error { + restoreStdout := ui.CaptureStdoutToTraceLog() + defer restoreStdout() + return runPackages(id, opts, args[0]) }, }, opts) diff --git a/test/cli/symlink_test.go b/test/cli/symlink_test.go index a81a0d9b8ca..97a01203861 100644 --- a/test/cli/symlink_test.go +++ b/test/cli/symlink_test.go @@ -1,8 +1,9 @@ package cli import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func Test_RequestedPathIncludesSymlink(t *testing.T) {