github.com/anchore/syft@v1.38.2/cmd/syft/internal/commands/root.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/anchore/clio"
     9  	"github.com/anchore/syft/cmd/syft/internal/ui"
    10  )
    11  
    12  func Root(app clio.Application, packagesCmd *cobra.Command) *cobra.Command {
    13  	id := app.ID()
    14  
    15  	opts := defaultScanOptions()
    16  
    17  	return app.SetupRootCommand(&cobra.Command{
    18  		Use:     fmt.Sprintf("%s [SOURCE]", app.ID().Name),
    19  		Short:   packagesCmd.Short,
    20  		Long:    packagesCmd.Long,
    21  		Args:    packagesCmd.Args,
    22  		Example: packagesCmd.Example,
    23  		PreRunE: applicationUpdateCheck(id, &opts.UpdateCheck),
    24  		RunE: func(cmd *cobra.Command, args []string) error {
    25  			restoreStdout := ui.CaptureStdoutToTraceLog()
    26  			defer restoreStdout()
    27  
    28  			return runScan(cmd.Context(), id, opts, args[0])
    29  		},
    30  	}, opts)
    31  }