Enhancement: extend command definition with option set
See original GitHub issueIn many commands we have a set of options where we require users to specify value for one of them, eg. in aad app get
, we require user to specify appId
, objectId
or name
. In all such cases, we implement validation logic in commands that checks if one of the options has been specified. We also check if only one of these options has been specified and not multiple. We repeat the validation for such options set in all commands. Instead, we should extend the command definition to allow commands to specify option sets. We should then extend the central validation logic, where we check if all required options have been specified, with checking if one option for each option set contains a value and return a relevant error message if that’s not the case.
class Command {
public optionSets(): string[][] | undefined {
return;
}
}
class AadAppGetCommand extends Command {
public optionSets(): string[][] | undefined {
return [
['appId', 'objectId', 'name']
];
}
}
In the central validation logic we enumerate option sets and check if for each set, one of the specified options has a value. If neither of the options in a set has a value, we return error like Specify either ${options.join(', ')}
. If more than one options have a value, we return error like Specify either ${options.join(', ')} but not multiple
.
Once we have this logic, we should identify and refactor all commands to define their option sets and remove the obsolete validation logic and tests.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:12 (11 by maintainers)
@waldekmastykarz sure, i will take a look at it
@vipulkelkar for now, let’s use our original idea as we outlined in the spec. We can revisit the schema-based validation in the future as it would be a larger refactoring.