Skip to content

Commit

Permalink
fix: ignore command CLI interface (#1211)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
elsapet committed Aug 25, 2023
1 parent 1601958 commit 2df8353
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e/flags/.snapshots/TestMetadataFlags-help
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Usage: bearer <command> [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:
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage: bearer <command> [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:
Expand Down
29 changes: 25 additions & 4 deletions pkg/commands/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ import (
)

func NewIgnoreCommand() *cobra.Command {
usageTemplate := `
Usage: bearer ignore <command> [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 <fingerprint> --author Mish --comment "investigate this"
# Show the details of an ignored fingerprint from your bearer.ignore file
$ bearer ignore show <fingerprint>
# Migrate existing ignored (excluded) fingerprints from bearer.yml file
# to bearer.ignore
$ bearer ignore migrate
`

cmd := &cobra.Command{
Use: "ignore [subcommand] <fingerprint>",
Short: "Manage ignored fingerprints",
Expand All @@ -26,6 +47,8 @@ func NewIgnoreCommand() *cobra.Command {
newIgnoreMigrateCommand(),
)

cmd.SetUsageTemplate(usageTemplate)

return cmd
}

Expand All @@ -37,8 +60,7 @@ func newIgnoreShowCommand() *cobra.Command {
$ bearer ignore show <fingerprint>`,
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 <fingerprint>\n")
return nil
return cmd.Help()
}

ignoredFingerprints, err := ignore.GetIgnoredFingerprints(nil)
Expand Down Expand Up @@ -78,8 +100,7 @@ $ bearer ignore add <fingerprint> --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 <fingerprint>\n")
return nil
return cmd.Help()
}

options, err := IgnoreAddFlags.ToOptions(args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/flag/ignore_add_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2df8353

Please sign in to comment.