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

options remain when reuse parse function #841

Closed
taehyeong224 opened this issue Aug 6, 2018 · 2 comments
Closed

options remain when reuse parse function #841

taehyeong224 opened this issue Aug 6, 2018 · 2 comments

Comments

@taehyeong224
Copy link

taehyeong224 commented Aug 6, 2018

var program = require('commander');
program
    .command('setup env')
    .option("-s, --setup_mode [mode]", "Which setup mode to use")
    .action((env, options) => {
        console.log("process.argv : ", process.argv)
        console.log("env : ", env)
        console.log("options : ", options.setup_mode)
        process.argv.splice(process.argv.length - 2, 2)
        program.parse(process.argv);
    });

program.parse(process.argv);
$node test.js setup env -s s

output

process.argv :  [ '/usr/local/bin/node',
  'path/test.js',
  'setup',
  'env',
  '-s',
  's' ]
env :  env
options :  s
process.argv :  [ '/usr/local/bin/node',
  'path/test.js',
  'setup',
  'env' ]
env :  env
options :  s

I changed 'process.argv' for some test, and I found options remain .

I expected options.setup_mode was undefined. but -s options not undefined.

@shadowspawn
Copy link
Collaborator

If you want to call parse multiple times, the best option is to create a fresh Command object.

See #438 for discussion and examples.

@shadowspawn
Copy link
Collaborator

Answer offered, and no further activity in six months.

Thank you for your contributions.

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

2 participants