Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ func EnrichCmd(c *components.Context) error {
func ScanCmd(c *components.Context) error {
if len(c.Arguments) == 0 && !c.IsFlagSet(flags.SpecFlag) {
return pluginsCommon.PrintHelpAndReturnError("providing either a <source pattern> argument or the 'spec' option is mandatory", c)
} else if len(c.Arguments) > 1 {
// If a non-existing flag was provided AFTER the provided source_pattern - it will be captured as another argument. Since 'scan' command
// Expects only a single argument, we use this check to verify all provided flags are valid.
// If a non exiting flag was provided BEFORE the source_pattern, the CLI will return an error before reaching this point.
return pluginsCommon.PrintHelpAndReturnError(utils.GetCliTooManyArgsErrorMessage(len(c.Arguments)), c)
}

serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ func splitEnvVar(envVar string) (key, value string) {
}
return split[0], strings.Join(split[1:], "=")
}

// This is a general error message for the CLI commands.
// Because of how command parsing is handled, improperly specified flags may be misinterpreted as arguments.
// Therefore, these flags will not go through the command's flags verifications, and will not be caught as incorrect flags.
func GetCliTooManyArgsErrorMessage(numberOfArguments int) string {
return fmt.Sprintf("Too many arguments provided (%d in total).\nSome flags may be incorrectly specified, causing them to be misinterpreted as arguments and ignored. Please verify that all flags are valid.", numberOfArguments)
}