fix: capture root command stdout (#2364)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow 2023-11-28 15:04:28 -05:00 committed by GitHub
parent ea4a6747eb
commit a50a0f77d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -1,8 +1,9 @@
package cli
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_RequestedPathIncludesSymlink(t *testing.T) {