-
Notifications
You must be signed in to change notification settings - Fork 993
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
Option completion doesn't work for commands #180
Comments
The parsing inside the command's handler is facilitated by a fresh instance of yargs. It would take a bit of work for to make completion work contextually, based on the command entered prior to the tab completion being hit. One could make the argument that this might be specific enough that we should just endorse that you implement it via a custom completion handler (the optional closure you can provide to completion). To argue the other side though, it would be a slick feature to have command-specific completion -- is this something you'd be interested in taking a stab at? |
@bcoe yeah, I'd be interested in tackling it. I may not have time for it until early next week. So if anybody else is game, please have at it. I'll leave word here when I start on it in earnest. |
Had a bit of time during a layover to look into this. It may end up being pretty straightforward: master...tschaub:command-completion This only works for commands with a handler that calls #!/usr/bin/env node
var argv = require('./index')
.help('help')
.completion()
.command('foo', 'foo command', function(yargs) {
var sub = yargs
.options({
bar: {
describe: 'bar option'
}
})
.completion()
.help('help')
.argv;
process.exit(0);
})
.command('bam', 'bam command', function(yargs) {
var sub = yargs
.options({
baz: {
describe: 'baz option'
}
})
.completion()
.help('help')
.argv;
process.exit(0);
})
.argv Needs testing and potentially more work. I'll try to pick it up later on. |
cool \o/ I was worried that would be much more of a pain. I'm also flying today, and am going to see about squashing a few more bugs on yargs. Question, how do you feel about the default completion handler also completing file names in the current working directory? I feel like this is something you usually want, but lose when you enable yargs' completion. Should we default to supporting this, or should the onus be on the developer to add this if they need it? |
@bcoe - I've opened #185 for command option completion (as noted there, this only works for commands one level deep). This is working well for the use cases I've tried. I'm sure it could be enhanced if there are more complex use cases.
That could be nice. One possible implementation in #186. Could also do |
@tschaub if you run:
https://github.com/bcoe/yargs/blob/master/CHANGELOG.md#v3130-20150624-0412-0000 If everything runs great, we can release the candidate tomorrow. |
nice |
Given this
test.js
script:Enabling completion:
And typing
./test.js bar --f
doesn't result in thefoo
option being completed.The text was updated successfully, but these errors were encountered: