You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, yargs outputs a usage string if any error is detected. Use the .showHelpOnFail() method to customize this behavior.
Params:
enable – If false, the usage string is not output.
message – Message that is output after the error message.
We are using it in the following manner:
exportconstbuilder=function(yargs: yargs.Argv): yargs.Argv{returnyargs.commandDir('feedback-commands',{extensions: ['js'],}).strict().showHelpOnFail(false,`Use ' --help' for usage`).demandCommand();};
However, the string passed in the parameter message is never displayed. Only the error message Not enough non-option arguments: got 0, need at least 1 is being displayed.
To be clear, we want to not display the help page but print a string after the error message instead.
PS: The string also doesn't get displayed when the parameter value is set true since --help output instead.
We are on version 17.0.1 but I tried with 17.0.3 as well and same result.
The text was updated successfully, but these errors were encountered:
showHelpOnFail doesn't display the message if it is chained onto yargs globally. It works as expected if chained onto the command builder, within command.
In the example below, only the showHelpOnFail that is chained onto the cmd1 builder has any effect.
yargs('cmd1 --opt1 hello --extraOpt oops').command('cmd1','cmd1 desc',yargs=>yargs.option('opt1',{alias: 'o',demandOption: true,}).showHelpOnFail(false,"What have you done????"),// this one worksargv=>console.log(argv)).showHelpOnFail(false,"What have you done????")// this one does nothing.strict().parse()
This is the output from the above example:
Unknown argument: extraOpt
What have you done????
I made a PR that would make the second showHelpOnFail work as well, but I will likely close it. (I feel it is unnecessary, and I'm nervous about the side effects of the solution)
The discrepancy between the global configuration of showHelpOnFail and the command builder feels a bit weird, but since there's a workaround, I advocate calling this a p2.
From the docs:
We are using it in the following manner:
However, the string passed in the parameter
message
is never displayed. Only the error messageNot enough non-option arguments: got 0, need at least 1
is being displayed.To be clear, we want to not display the help page but print a string after the error message instead.
PS: The string also doesn't get displayed when the parameter value is set true since
--help
output instead.We are on version
17.0.1
but I tried with17.0.3
as well and same result.The text was updated successfully, but these errors were encountered: