Skip to content

Commit

Permalink
chore: removes changes to db diff, db serach and db list commands
Browse files Browse the repository at this point in the history
Signed-off-by: Adnan Gulegulzar <gulegulzaradnan@gmail.com>
  • Loading branch information
ADorigi committed Oct 22, 2024
1 parent f2dac42 commit 7e7ba5e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
3 changes: 1 addition & 2 deletions cmd/grype/cli/commands/db_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/grype/differ"
"github.com/anchore/grype/internal"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
)
Expand All @@ -30,7 +29,7 @@ func (d *dbDiffOptions) AddFlags(flags clio.FlagSet) {

func DBDiff(app clio.Application) *cobra.Command {
opts := &dbDiffOptions{
Output: internal.TableOutputFormat,
Output: "table",
DBOptions: *dbOptionsDefault(app.ID()),
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/grype/cli/commands/db_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal"
)

type dbListOptions struct {
Expand All @@ -25,7 +24,7 @@ func (d *dbListOptions) AddFlags(flags clio.FlagSet) {

func DBList(app clio.Application) *cobra.Command {
opts := &dbListOptions{
Output: internal.TextOutputFormat,
Output: "text",
DBOptions: *dbOptionsDefault(app.ID()),
}

Expand Down Expand Up @@ -59,7 +58,7 @@ func runDBList(opts *dbListOptions) error {
}

switch opts.Output {
case internal.TextOutputFormat:
case "text":
// summarize each listing entry for the current DB schema
for _, l := range available {
fmt.Printf("Built: %s\n", l.Built)
Expand All @@ -68,15 +67,15 @@ func runDBList(opts *dbListOptions) error {
}

fmt.Printf("%d databases available for schema %d\n", len(available), supportedSchema)
case internal.JSONOutputFormat:
case "json":
// show entries for the current schema
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(&available); err != nil {
return fmt.Errorf("failed to db listing information: %+v", err)
}
case internal.RawOutputFormat:
case "raw":
// show the entire listing file
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
Expand Down
2 changes: 0 additions & 2 deletions cmd/grype/cli/commands/db_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func DBProviders(app clio.Application) *cobra.Command {
}

func runDBProviders(opts *dbProvidersOptions, app clio.Application) error {

metadataFileLocation, err := getMetadataFileLocation(app)
if err != nil {
return nil
Expand Down Expand Up @@ -83,7 +82,6 @@ func runDBProviders(opts *dbProvidersOptions, app clio.Application) error {
}

func getMetadataFileLocation(app clio.Application) (*string, error) {

dbCurator, err := distribution.NewCurator(dbOptionsDefault(app.ID()).DB.ToCuratorConfig())
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions cmd/grype/cli/commands/db_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func TestGetDBProviders(t *testing.T) {
fileLocation: "./test-fixtures",
expectedProviders: dbProviders{
Providers: []dbProviderMetadata{
dbProviderMetadata{
{
Name: "provider1",
LastSuccessfulRun: "2024-10-16T01:33:16.844201Z",
},
dbProviderMetadata{
{
Name: "provider2",
LastSuccessfulRun: "2024-10-16T01:32:43.516596Z",
},
Expand Down Expand Up @@ -70,11 +70,11 @@ func TestDisplayDBProvidersTable(t *testing.T) {
name: "display providers table",
providers: dbProviders{
Providers: []dbProviderMetadata{
dbProviderMetadata{
{
Name: "provider1",
LastSuccessfulRun: "2024-10-16T01:33:16.844201Z",
},
dbProviderMetadata{
{
Name: "provider2",
LastSuccessfulRun: "2024-10-16T01:32:43.516596Z",
},
Expand Down Expand Up @@ -114,11 +114,11 @@ func TestDisplayDBProvidersJSON(t *testing.T) {
name: "display providers table",
providers: dbProviders{
Providers: []dbProviderMetadata{
dbProviderMetadata{
{
Name: "provider1",
LastSuccessfulRun: "2024-10-16T01:33:16.844201Z",
},
dbProviderMetadata{
{
Name: "provider2",
LastSuccessfulRun: "2024-10-16T01:32:43.516596Z",
},
Expand Down
7 changes: 3 additions & 4 deletions cmd/grype/cli/commands/db_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/anchore/clio"
"github.com/anchore/grype/grype"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
)
Expand All @@ -30,7 +29,7 @@ func (c *dbQueryOptions) AddFlags(flags clio.FlagSet) {

func DBSearch(app clio.Application) *cobra.Command {
opts := &dbQueryOptions{
Output: internal.TableOutputFormat,
Output: "table",
DBOptions: *dbOptionsDefault(app.ID()),
}

Expand Down Expand Up @@ -78,7 +77,7 @@ func present(outputFormat string, vulnerabilities []vulnerability.Vulnerability,
}

switch outputFormat {
case internal.TableOutputFormat:
case "table":
rows := [][]string{}
for _, v := range vulnerabilities {
rows = append(rows, []string{v.ID, v.PackageName, v.Namespace, v.Constraint.String()})
Expand All @@ -103,7 +102,7 @@ func present(outputFormat string, vulnerabilities []vulnerability.Vulnerability,

table.AppendBulk(rows)
table.Render()
case internal.JSONOutputFormat:
case "json":
enc := json.NewEncoder(output)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
Expand Down

0 comments on commit 7e7ba5e

Please # to comment.