Skip to content

Commit

Permalink
fix: capture root command stdout (#2364)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow authored Nov 28, 2023
1 parent ea4a674 commit a50a0f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/syft/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions cmd/syft/cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/cli/symlink_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cli

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_RequestedPathIncludesSymlink(t *testing.T) {
Expand Down

0 comments on commit a50a0f7

Please sign in to comment.