Discussed in #2383
Originally posted by waldekmastykarz April 22, 2021
Today, when you run a command and haven't specified a required option, the command will fail with an error. What if instead, we'd show a prompt allowing you to specify a value? It would be more user-friendly than just failing with an error and showing help.
In some commands we offer the user an option to specify one of the few options, like appId or appName. Since both are optional, they wouldn't be picked up by the prompt as a missing required option and the command would fail anyway at the validation stage. We could think of a solution for this but perhaps that's not necessary at the start.
We could expose this behavior behind an option, in case you use CLI in a script and don't want the script to get stuck on a prompt that you wouldn't be able to respond to.
What do you think, would this be worth the effort?
Since this introduces a change in CLI's behavior, let's put it behind a configuration flag that we can enable by default, but which folks can disable if they want to keep the current behavior (missing required property > error).
For the prompts, we should use inquirer, which we already use for confirm prompts in remove commands. Here's where we validate required options so this would be the place to extend with checking the config flag and showing prompts:
|
return this.closeWithError(`Required option ${this.commandToExecute.options[i].name} not specified`, this.optionsFromArgs, true); |
Discussed in #2383
Originally posted by waldekmastykarz April 22, 2021
Today, when you run a command and haven't specified a required option, the command will fail with an error. What if instead, we'd show a prompt allowing you to specify a value? It would be more user-friendly than just failing with an error and showing help.
In some commands we offer the user an option to specify one of the few options, like
appIdorappName. Since both are optional, they wouldn't be picked up by the prompt as a missing required option and the command would fail anyway at the validation stage. We could think of a solution for this but perhaps that's not necessary at the start.We could expose this behavior behind an option, in case you use CLI in a script and don't want the script to get stuck on a prompt that you wouldn't be able to respond to.
What do you think, would this be worth the effort?
Since this introduces a change in CLI's behavior, let's put it behind a configuration flag that we can enable by default, but which folks can disable if they want to keep the current behavior (missing required property > error).
For the prompts, we should use inquirer, which we already use for confirm prompts in
removecommands. Here's where we validate required options so this would be the place to extend with checking the config flag and showing prompts:cli-microsoft365/src/cli/Cli.ts
Line 158 in 872c7ee