-
Notifications
You must be signed in to change notification settings - Fork 991
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
Avoid help, version, validation, and the completion command while handling the completion option #178
Conversation
It looks like option completion is also not working as expected with aliases. Given the following #!/usr/bin/env node
var argv = require('./index')
.completion('completion')
.help('help')
.alias('help', 'h')
.strict()
.argv;
console.log('argv: %j', argv); Setting up completion: $ eval "$( ./test.js completion )" And then typing
(note the trailing comma) |
In 856db9c, the completion option is always handled before the help or version options. Previously, the order options were handled depended on the order of It would be cleaner to separate the |
In 2c64dd0, the completion option is handled before the completion command. Without this change, |
We were 100% on the same page with regards to these fixes, I'm only opting for #181 since it has a patch for the infinite problem. |
No problem. The changes in #181 look good. I'll test out the branch now. |
While handling the completion option,
parseArgs
is called with a "partial" set of arguments. With strict parsing, these partial arguments may cause the task to exit with an error. This screws up completion. See #177 for an example script.The changes here add a
parseOnly
argument to theparse
method. While the completion values are being determined,yargs.parse(args, true)
is called to avoid validation. This allows people to complete options whose partial values may not be valid options.The test helper needed to be updated so that logging doesn't continue after
process.exit()
has been called. While processing the--get-yargs-completions
option in the tests, the call toprocess.exit()
doesn't stop execution, and errors were being logged aboutget-yargs-completions
being an unknown argument. To make an assertion about there being no logged errors in the tests, the helper stops errors from being logged afterprocess.exit()
has been called.Fixes #177.
Fixes #179.