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
.help(false) does not disable --help when used in a default command #1516
Comments
Reproduced with master branch. |
Oups! Sorry, inverted I cannot reproduce this issue with the following test code, using either 15.0.2, 15.1.0 or master branch: index.jsconst yargs = require('yargs')
console.log(
yargs
.help(false)
.parse()
)
$ node index.js --help
{ _: [], help: true, '$0': 'index.js' } @daguej Could you please provide a sample code reproducing this issue? |
@mleguen looks like my situation was a bit complex. You have to have a default command with help disabled and another command with help enabled. var yargs = require('yargs');
var argv = yargs
.command('foo', 'bar', function(yargs) {
yargs.option('baz', {
describe: 'qux'
})
})
.command('*', 'foo', function(yargs) {
yargs
.option('help', {
boolean: true
})
.help(false)
})
.argv;
console.log(argv); Tested against master/v15.1.0 (7fdb3e7).
|
@daguej If I understand well what you are intending to do:
I doubt this is a use case we would cover. However, we should state in the doc that |
@mleguen Yes, you understand my intention. I want to manually handle the display of help content for my default command, but let yargs handle help for all other commands. Are you sure that A quick reading of the code shows that I can get my desired behavior by inverting how I call var yargs = require('yargs');
var argv = yargs
.command('foo', '2', function(yargs) {
yargs.option('baz', {
describe: 'opt'
})
.help()
})
.command('bar', '3', function(yargs) {
yargs.option('qux', {
describe: 'opt'
})
.help('info')
})
.command('*', '1', function(yargs) {
yargs
.option('help', {
boolean: true
})
})
.help(false)
.argv;
console.log(argv);
And, having help enabled globally and disabling it selectively in normal commands also works: var yargs = require('yargs');
var argv = yargs
.command('foo', '2', function(yargs) {
yargs.option('baz', {
describe: 'opt'
})
.help(false)
})
.argv;
console.log(argv);
So it's only when a default command is involved that the behavior of This wouldn't be the first time there's a bug with default command help: #810 |
@daguej Thanks for your analysis. In fact this occurs only when there is other commands, or when the default command has no aliases, and I think it is rather a wanted behavior than a bug (set As I understand it, yargs distinguishes global help and default command help:
The only exception is when there are neither other commands, nor aliases to the default command. In that case, yargs replaces the global help (which would have no interest) by the default command help. So in your use case, as you stated, you indeed have first to disable the global help, then to reenable it in the commands where you do not want to handle help yourself. |
true opensource! |
|
.help(false)
does not appear to be working correctly in v15.0.2 when used in a default command. It does hide the--help
option from the help text, but yargs still prints the help text if you runmyapp --help
ormyapp help
.This is contrary to the docs, which say
I got the desired behavior (ie, yargs did nothing with
--help
) in v8.0.2 by not calling.help(…)
at all. I noticed this issue when trying to upgrade.The text was updated successfully, but these errors were encountered: