diff --git a/cmd/grype/cli/commands/db_check.go b/cmd/grype/cli/commands/db_check.go index a5b8a02ad61..b9bf16a49e9 100644 --- a/cmd/grype/cli/commands/db_check.go +++ b/cmd/grype/cli/commands/db_check.go @@ -36,7 +36,7 @@ func DBCheck(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "check", Short: "check to see if there is a database update available", PreRunE: func(cmd *cobra.Command, args []string) error { @@ -48,7 +48,15 @@ func DBCheck(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, _ []string) error { return runDBCheck(*opts) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbCheckOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBCheck(opts dbCheckOptions) error { diff --git a/cmd/grype/cli/commands/db_delete.go b/cmd/grype/cli/commands/db_delete.go index 4d4ef142c55..185a90134b4 100644 --- a/cmd/grype/cli/commands/db_delete.go +++ b/cmd/grype/cli/commands/db_delete.go @@ -15,7 +15,7 @@ import ( func DBDelete(app clio.Application) *cobra.Command { opts := dbOptionsDefault(app.ID()) - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "delete", Short: "delete the vulnerability database", Args: cobra.ExactArgs(0), @@ -23,7 +23,14 @@ func DBDelete(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, _ []string) error { return runDBDelete(*opts) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{opts}) } func runDBDelete(opts DBOptions) error { diff --git a/cmd/grype/cli/commands/db_diff.go b/cmd/grype/cli/commands/db_diff.go index 6ff85f3eafb..67d00a397a5 100644 --- a/cmd/grype/cli/commands/db_diff.go +++ b/cmd/grype/cli/commands/db_diff.go @@ -33,7 +33,7 @@ func DBDiff(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "diff [flags] base_db_url target_db_url", Short: "diff two DBs and display the result", Args: cobra.MaximumNArgs(2), @@ -61,7 +61,15 @@ func DBDiff(app clio.Application) *cobra.Command { return runDBDiff(opts, base, target) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbDiffOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBDiff(opts *dbDiffOptions, base string, target string) (errs error) { diff --git a/cmd/grype/cli/commands/db_import.go b/cmd/grype/cli/commands/db_import.go index 1f98c17b841..7e774dc10d7 100644 --- a/cmd/grype/cli/commands/db_import.go +++ b/cmd/grype/cli/commands/db_import.go @@ -17,7 +17,7 @@ import ( func DBImport(app clio.Application) *cobra.Command { opts := dbOptionsDefault(app.ID()) - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "import FILE", Short: "import a vulnerability database archive", Long: fmt.Sprintf("import a vulnerability database archive from a local FILE.\nDB archives can be obtained from %q.", internal.DBUpdateURL), @@ -25,7 +25,14 @@ func DBImport(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, args []string) error { return runDBImport(*opts, args[0]) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{opts}) } func runDBImport(opts DBOptions, dbArchivePath string) error { diff --git a/cmd/grype/cli/commands/db_list.go b/cmd/grype/cli/commands/db_list.go index e02f4de553e..b64c564c2e8 100644 --- a/cmd/grype/cli/commands/db_list.go +++ b/cmd/grype/cli/commands/db_list.go @@ -32,7 +32,7 @@ func DBList(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "list", Short: "list all DBs available according to the listing URL", PreRunE: disableUI(app), @@ -40,7 +40,15 @@ func DBList(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, _ []string) error { return runDBList(*opts) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbListOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBList(opts dbListOptions) error { diff --git a/cmd/grype/cli/commands/db_providers.go b/cmd/grype/cli/commands/db_providers.go index c59bf6feb12..4d24d3d78c4 100644 --- a/cmd/grype/cli/commands/db_providers.go +++ b/cmd/grype/cli/commands/db_providers.go @@ -37,14 +37,22 @@ func DBProviders(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "providers", Short: "list vulnerability database providers", Args: cobra.ExactArgs(0), RunE: func(_ *cobra.Command, _ []string) error { return runDBProviders(opts, app) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbProvidersOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBProviders(opts *dbProvidersOptions, app clio.Application) error { diff --git a/cmd/grype/cli/commands/db_search.go b/cmd/grype/cli/commands/db_search.go index 1e1af4492af..015fb329110 100644 --- a/cmd/grype/cli/commands/db_search.go +++ b/cmd/grype/cli/commands/db_search.go @@ -36,7 +36,7 @@ func DBSearch(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "search [vulnerability_id]", Short: "get information on a vulnerability from the db", Args: cobra.ExactArgs(1), @@ -44,7 +44,15 @@ func DBSearch(app clio.Application) *cobra.Command { id := args[0] return runDBSearch(*opts, id) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbQueryOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBSearch(opts dbQueryOptions, vulnerabilityID string) error { diff --git a/cmd/grype/cli/commands/db_status.go b/cmd/grype/cli/commands/db_status.go index 35643ded326..0b91589ec95 100644 --- a/cmd/grype/cli/commands/db_status.go +++ b/cmd/grype/cli/commands/db_status.go @@ -32,7 +32,7 @@ func DBStatus(app clio.Application) *cobra.Command { DBOptions: *dbOptionsDefault(app.ID()), } - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "status", Short: "display database status", Args: cobra.ExactArgs(0), @@ -40,7 +40,15 @@ func DBStatus(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, _ []string) error { return runDBStatus(*opts) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Hidden *dbStatusOptions `json:"-" yaml:"-" mapstructure:"-"` + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{Hidden: opts, DBOptions: &opts.DBOptions}) } func runDBStatus(opts dbStatusOptions) error { diff --git a/cmd/grype/cli/commands/db_update.go b/cmd/grype/cli/commands/db_update.go index aa153aeaf67..7a0f1bc6d6e 100644 --- a/cmd/grype/cli/commands/db_update.go +++ b/cmd/grype/cli/commands/db_update.go @@ -17,7 +17,7 @@ import ( func DBUpdate(app clio.Application) *cobra.Command { opts := dbOptionsDefault(app.ID()) - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "update", Short: "download the latest vulnerability database", Args: cobra.ExactArgs(0), @@ -29,7 +29,14 @@ func DBUpdate(app clio.Application) *cobra.Command { RunE: func(_ *cobra.Command, _ []string) error { return runDBUpdate(opts.DB, opts.Experimental.DBv6) }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + *DBOptions `yaml:",inline" mapstructure:",squash"` + } + + return app.SetupCommand(cmd, &configWrapper{opts}) } func runDBUpdate(opts options.Database, expUseV6 bool) error { diff --git a/cmd/grype/cli/commands/explain.go b/cmd/grype/cli/commands/explain.go index 6770a17f468..36031b46654 100644 --- a/cmd/grype/cli/commands/explain.go +++ b/cmd/grype/cli/commands/explain.go @@ -27,7 +27,7 @@ func (d *explainOptions) AddFlags(flags clio.FlagSet) { func Explain(app clio.Application) *cobra.Command { opts := &explainOptions{} - return app.SetupCommand(&cobra.Command{ + cmd := &cobra.Command{ Use: "explain --id [VULNERABILITY ID]", Short: "Ask grype to explain a set of findings", PreRunE: disableUI(app), @@ -53,5 +53,12 @@ func Explain(app clio.Application) *cobra.Command { // TODO: implement return fmt.Errorf("requires grype json on stdin, please run 'grype -o json ... | grype explain ...'") }, - }, opts) + } + + // prevent from being shown in the grype config + type configWrapper struct { + Opts *explainOptions `json:"-" yaml:"-" mapstructure:"-"` + } + + return app.SetupCommand(cmd, &configWrapper{opts}) }