-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to provide examples of possible values when required option is not passed #2229
Comments
The default error handling shows the flags specified when the option was added. So there is a little information from the text for the option-value. program.requiredOption('--docker-image <image-name>', 'choose docker image'); % node index.mjs
error: required option '--docker-image <image-name>' not specified |
There isn't a way to attach custom error messages to a particular option. You could manually override the error message by using a try/catch (and |
Thanks for the information! Indeed, seems quite cumbersome to do in that case |
Providing extra information for a particular type of error is easier than a custom error per option, like: program
.exitOverride()
.requiredOption('--docker-image <image-name>', 'choose docker image');
try {
program.parse();
} catch (err) {
if (err.code === 'commander.missingMandatoryOptionValue') {
process.stderr.write('Example values for --docker-image are foo, bar\n');
}
process.exitCode = 1;
} % node custom.mjs
error: required option '--docker-image <image-name>' not specified
Example values for --docker-image are foo, bar |
Interesting! 🙏 But what if I have multiple commands (in my case)? |
Multiple commands with different required options? Hmmm... Ok, I think you could override (Want to see an example of that?) |
An answer was provided, and no further activity in a month. Closing this as resolved. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
Let's say that option
--docker-image
is required.The user calls the command without specifying it. Commander.js will say that --docker-image must be provided. However, it might not be obvious for the user what is an example of value that would be accepted by this option.
Would there be a way to give examples of values for required options not passed?
The text was updated successfully, but these errors were encountered: