Skip to content

Enhancement: extend command definition with option set #2998

@waldekmastykarz

Description

@waldekmastykarz

In 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions