Skip to content

Commit

Permalink
fix: Improve parsing of boolean action parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Oct 30, 2024
1 parent 27d5a1a commit d3b6f4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private static final void addOptionDescriptor(List<IOptionDescriptor> result, Ac
.name(getOptionName(parameter.getName()))
.aliases(getOptionAliases(parameter.getCliAliasesArray()))
.description(parameter.getDescription())
.bool(parameter.getType()!=null && parameter.getType().equals("boolean"))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static interface IOptionDescriptor {
String getName();
List<String> getAliases();
String getDescription();
boolean isBool();

default String getOptionNamesAndAliasesString(String delimiter) {
var name = getName();
Expand All @@ -59,6 +60,7 @@ public static class OptionDescriptor implements IOptionDescriptor {
private final String name;
private final List<String> aliases;
private final String description;
private final boolean bool;
}

@Data
Expand Down Expand Up @@ -107,13 +109,16 @@ private Map<String, String> parseArgs(List<String> validationErrors, String[] ar
var argWithPossibleValue = argsDeque.pop();
var argElts = argWithPossibleValue.split("=", 2);
var arg = argElts[0];
if ( !optionsByNameAndAliases.containsKey(arg) ) {
var optionDescriptor = optionsByNameAndAliases.get(arg);
if ( optionDescriptor==null ) {
validationErrors.add("Unknown command line option: "+arg);
} else if ( argElts.length==2 ) {
result.put(arg, argElts[1]);
} else {
var nextArg = argsDeque.peek();
var value = optionsByNameAndAliases.containsKey(nextArg) ? null : argsDeque.pop();
var value = nextArg==null || optionsByNameAndAliases.containsKey(nextArg)
? (optionDescriptor.isBool() ? "true" : null)
: argsDeque.pop();
result.put(arg, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ parameters:
- group: sast_setup_opts
required: false
name: use-aviator
description: "See `fcli fod sast-scan setup`"
description: "See `fcli fod sast-scan setup`"
type: boolean
- group: sast_setup_opts
required: false
name: oss
description: "See `fcli fod sast-scan setup`"
type: boolean
- name: attributes
required: false
cliAliases: attrs
Expand Down

0 comments on commit d3b6f4c

Please sign in to comment.