Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail 'jf scan' when a wrong flag is provided after command's arguments #165

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ func EnrichCmd(c *components.Context) error {
func ScanCmd(c *components.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does docker scan uses the same flow as ScanCmd? or should implement it there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is using dockerCmd that resides in CLI. I initiated another PR to ecosystem:
jfrog/jfrog-cli#2686

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hadarshjfrog Since resolving the same issue in 'jf docker scan' should be done by Ecosystem and this is not a top priority for them. Since this is not going to happen soon and I dont want to miss the fix Iv'e already worked on im proceeding without 'jf docker scan' and we can open a ticket for the Ecosystem about this

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 {
log.Warn(utils.GetCliTooManyArgsErrorMessage(len(c.Arguments), c.CommandName))
}
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved

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

// This is a general error message for the CLI commands.
// Due to the way we parse the commands, in some cases flags might be mistaken as arguments and therefore they will not go though the command's flags verifications.
// When this happens it could prevent the flag from affecting the command as intended. This error message informes the user about this issue
func GetCliTooManyArgsErrorMessage(numberOfArguments int, commandName string) string {
return fmt.Sprintf("Too many arguments provided (%d in total).\n"+
"Some flags might be mistaken as arguments and ignored, which could prevent them from affecting the command as intended.\n"+
"Please ensure all provided flags are valid and provided correct order. For more details: 'jf %s --help'", numberOfArguments, commandName)
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved
}
Loading