From 2df83531f562afc9cc033035584e2e3f86f8fd4e Mon Sep 17 00:00:00 2001 From: elsapet Date: Fri, 25 Aug 2023 16:29:11 +0200 Subject: [PATCH] fix: ignore command CLI interface (#1211) * fix: add ignore to Available Commands list * fix: add usage template for bearer ignore * fix: copy pasta for ignore add author flag * fix: show usage template when no fingerprint given * chore: update stale snapshot --- e2e/flags/.snapshots/TestMetadataFlags-help | 1 + pkg/commands/app.go | 1 + pkg/commands/ignore.go | 29 ++++++++++++++++++--- pkg/flag/ignore_add_flags.go | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/e2e/flags/.snapshots/TestMetadataFlags-help b/e2e/flags/.snapshots/TestMetadataFlags-help index 1476a5051..993ad77ae 100644 --- a/e2e/flags/.snapshots/TestMetadataFlags-help +++ b/e2e/flags/.snapshots/TestMetadataFlags-help @@ -12,6 +12,7 @@ Usage: bearer [flags] Available Commands: scan Scan a directory or file init Write the default config to bearer.yml + ignore Manage ignored fingerprints version Print the version Examples: diff --git a/pkg/commands/app.go b/pkg/commands/app.go index 6f23471b5..73c0914d4 100644 --- a/pkg/commands/app.go +++ b/pkg/commands/app.go @@ -42,6 +42,7 @@ Usage: bearer [flags] Available Commands: scan Scan a directory or file init Write the default config to bearer.yml + ignore Manage ignored fingerprints version Print the version Examples: diff --git a/pkg/commands/ignore.go b/pkg/commands/ignore.go index d6d47338c..613666e43 100644 --- a/pkg/commands/ignore.go +++ b/pkg/commands/ignore.go @@ -12,6 +12,27 @@ import ( ) func NewIgnoreCommand() *cobra.Command { + usageTemplate := ` +Usage: bearer ignore [flags] + +Available Commands: + add Add an ignored fingerprint + show Show an ignored fingerprint + migrate Migrate ignored fingerprints + +Examples: + # Add an ignored fingerprint to your bearer.ignore file + $ bearer ignore add --author Mish --comment "investigate this" + + # Show the details of an ignored fingerprint from your bearer.ignore file + $ bearer ignore show + + # Migrate existing ignored (excluded) fingerprints from bearer.yml file + # to bearer.ignore + $ bearer ignore migrate + +` + cmd := &cobra.Command{ Use: "ignore [subcommand] ", Short: "Manage ignored fingerprints", @@ -26,6 +47,8 @@ func NewIgnoreCommand() *cobra.Command { newIgnoreMigrateCommand(), ) + cmd.SetUsageTemplate(usageTemplate) + return cmd } @@ -37,8 +60,7 @@ func newIgnoreShowCommand() *cobra.Command { $ bearer ignore show `, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { - cmd.Printf("No fingerprint given. Please provide a fingerprint with the command: $ bearer ignore show \n") - return nil + return cmd.Help() } ignoredFingerprints, err := ignore.GetIgnoredFingerprints(nil) @@ -78,8 +100,7 @@ $ bearer ignore add --author Mish --comment "Possible false positi } if len(args) == 0 { - cmd.Printf("No fingerprint given. Please provide a fingerprint with the command: $ bearer ignore add \n") - return nil + return cmd.Help() } options, err := IgnoreAddFlags.ToOptions(args) diff --git a/pkg/flag/ignore_add_flags.go b/pkg/flag/ignore_add_flags.go index a45876639..85e615b9b 100644 --- a/pkg/flag/ignore_add_flags.go +++ b/pkg/flag/ignore_add_flags.go @@ -6,7 +6,7 @@ var ( ConfigName: "ignore_add.author", Shorthand: "a", Value: FormatEmpty, - Usage: "Specify report format (json, yaml, sarif, gitlab-sast, rdjson, html)", + Usage: "Add author information to this ignored finding.", } CommentFlag = Flag{ Name: "comment",