Skip to content

Enhancement: Conditionally required options #5636

@martinlingstuyl

Description

@martinlingstuyl

There are quite some situations in our codebase where options aren't required, except when another option has a certain value. Like the --password option on m365 login, that's required for --authType password.

Another example is the people profilecardproperty <verb> commands, where --displayName is required when executed on a customAttribute.

This is unfortunate, for example because the prompt for required options does not work for these options.

💡Idea

Let's allow for conditionally required options in the CLI engine.

We can do this by Adding a requiredWhen property to the option interface: requiredWhen: (args:any) => boolean, and adding an extra loop for these kinds of options after required options are validated and prompted on.

For example for the m365 login --authType password example. This would work as follows:

{
    option: '-p, --password [password]',
    requiredWhen: (args:any) => args.options.authType === 'password'
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions