Skip to content

Commit

Permalink
Also set aliases, camel case, and kebab case options
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew W. Harn <[email protected]>
  • Loading branch information
awharn committed Aug 21, 2024
1 parent 184bb4c commit 708e04c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ export class SyntaxValidator {
if (positional.type === "number") {
valid = this.validateNumeric(commandArguments[positional.name], positional, responseObject, true) && valid;
// Convert to number for backwards compatability
if (valid) { commandArguments[positional.name] = parseFloat(commandArguments[positional.name]); }
if (valid) {
const changedOptions: ICommandArguments = CliUtils.setOptionValue(positional.name,
[], parseFloat(commandArguments[positional.name]));
for (const [k, v] of Object.entries(changedOptions)) {
commandArguments[k] = v;
}
}
}

if (!(positional.stringLengthRange == null) &&
Expand Down Expand Up @@ -378,8 +384,14 @@ export class SyntaxValidator {
valid = this.validateBoolean(commandArguments[optionDef.name], optionDef, responseObject) && valid;
} else if (optionDef.type === "number") {
valid = this.validateNumeric(commandArguments[optionDef.name], optionDef, responseObject) && valid;
// Convert to numbers for backwards compatibility
if (valid) { commandArguments[optionDef.name] = parseFloat(commandArguments[optionDef.name]); }
// Convert to numbers for backwards compatibility - sets all possible values
if (valid) {
const changedOptions: ICommandArguments = CliUtils.setOptionValue(optionDef.name,
optionDef.aliases ?? [], parseFloat(commandArguments[optionDef.name]));
for (const [k, v] of Object.entries(changedOptions)) {
commandArguments[k] = v;
}
}
}
/**
* Validate that the option's value is valid json.
Expand Down

0 comments on commit 708e04c

Please sign in to comment.