Skip to content
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

It causes unexpected result if arguments are the same as option name #483

Closed
zlargon opened this issue Jan 2, 2016 · 6 comments
Closed

Comments

@zlargon
Copy link

zlargon commented Jan 2, 2016

This issue is quite similar to #471.

var program = require('commander');

program
  .option('-f, --foo', 'add some foo')
  .parse(['node', './test.js', 'foo']);

console.log(program.args);  // program.args = []
console.log(program.foo);   // program.foo = []

// Expected Result:
// program.args = ['foo']
// program.foo = undefined
@SomeKittens
Copy link
Collaborator

I'm not quite ready to say this is a dupe of #471, as 'version' is somewhat internal, and you've added foo.

@ericuldall
Copy link

The bug is with Command.prototype.parseOptions:

When looping over the options passed it accepts any values. It should perhaps only accept values that .match(/^-.*/)

@ericuldall
Copy link

I've added a fix proposal to pull request #517

@ericuldall
Copy link

The "fix" seems to be breaking other features, per failed unit tests. I'm not sure what or why at this point. Once the two play nice it should be useable.

@ericuldall
Copy link

It looks like many of the unit tests don't work when this functionality is fixed. Many of them pass options that are not defined as .option. So now the tests are throwing the error:

error: unknown option `--setup_mode'

To me, this seems like the correct behavior, though these will not pass a travis-ci build.

@shadowspawn
Copy link
Collaborator

Closing as duplicate of #346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants