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

Fix a bug with variadic argument #291

Merged
merged 2 commits into from
Dec 2, 2014
Merged

Fix a bug with variadic argument #291

merged 2 commits into from
Dec 2, 2014

Conversation

Quentin01
Copy link
Contributor

I noticed that with a variadic argument, program.args contains additional arguments at the end.
For example:

#!/usr/bin/env node

'use strict';

var program = require('commander');

program
  .version('0.0.1');

program
  .command('stats [files...]')
  .action(function stats(files) {
    console.log(program.args);
  });

program.parse(process.argv);

And the output:

$ ./program.js stats test1 test2 test3 test4
[ [ 'test1', 'test2', 'test3' ],
  { commands: [],
    options: [],
    _execs: [],
    _args: [ [Object] ],
    _name: 'stats',
    parent: 
     { commands: [Object],
       options: [Object],
       _execs: [],
       _args: [],
       _name: 'bug',
       Command: [Function: Command],
       Option: [Function: Option],
       _version: '0.0.1',
       _events: [Object],
       rawArgs: [Object],
       args: [Circular] } },
  'test3' ,
  'test4' ]

My fix remove residues of arguments at the end of program.args

@zhiyelee
Copy link
Collaborator

zhiyelee commented Dec 2, 2014

Thx @Quentin01 , would u mind adding a test for this fix?

@Quentin01
Copy link
Contributor Author

@zhiyelee Done. It does not pass before my fix.

zhiyelee added a commit that referenced this pull request Dec 2, 2014
Fix a bug with variadic argument.
@zhiyelee zhiyelee merged commit 875e498 into tj:master Dec 2, 2014
@zhiyelee zhiyelee mentioned this pull request Dec 15, 2014
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

Successfully merging this pull request may close these issues.

2 participants