-
-
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
sub-command args seem off #56
Comments
Fix issue #56 where options parsing strips off arguments that it shouldn't
@visionmedia @orthlieb This code doesn't work when a boolean option is placed in between two required arguments. Pull request #75 is a more comprehensive solution to this problem that takes care of this case. To see the issue, consider the following command: #!/usr/bin/env node
var program = require('commander');
program.command('greet <firstName> <lastName>')
.option('-e, --example', 'Example boolean option')
.action(function(firstName, lastName, env) {
console.log('Hello ' + firstName + ' ' + lastName);
});
program.parse(process.argv); When this is run normally, everything seems to work fine: $ ./cmd.js greet -e john doe
Hello john doe But when this is run with the boolean option $ ./cmd.js greet john -e doe
Hello doe john which is incorrect. This inversion of arguments occurs because the parsed argument "doe" is inserted prior to "john" incorrectly. You cannot assume that leftover parsed arguments from options always go before other arguments. Instead, the position of each parsed argument needs to be tracked, and then these arguments must be reinserted in the order in which they were specified. This problem is solved in pull request #75, in which I took this case into account. |
Thanks! |
for example
component build <path> <dst>
should allow options afterbuild
specific tothe sub-command:
component build --stylus foo bar
, however it fails and currentlyneeds to be
component build foo bar --stylus
The text was updated successfully, but these errors were encountered: