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'
}
There are quite some situations in our codebase where options aren't required, except when another option has a certain value. Like the
--passwordoption onm365 login, that's required for--authType password.Another example is the
people profilecardproperty <verb>commands, where--displayNameis 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 passwordexample. This would work as follows: