Skip to content

Commit

Permalink
Clean up config help text (#2347)
Browse files Browse the repository at this point in the history
* clean up config

Signed-off-by: Alex Goodman <[email protected]>

* expose DB options

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Jan 8, 2025
1 parent 79d86e0 commit 7cae8a3
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 20 deletions.
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions cmd/grype/cli/commands/db_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ 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),
PreRunE: disableUI(app),
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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions cmd/grype/cli/commands/db_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ 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),
Args: cobra.ExactArgs(1),
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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ 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),
Args: cobra.ExactArgs(0),
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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ 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),
RunE: func(_ *cobra.Command, args []string) (err error) {
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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/grype/cli/commands/db_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ 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),
PreRunE: disableUI(app),
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 {
Expand Down
11 changes: 9 additions & 2 deletions cmd/grype/cli/commands/db_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions cmd/grype/cli/commands/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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})
}

0 comments on commit 7cae8a3

Please sign in to comment.