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

Unknown options are not passed into options #1445

Closed
CyberGl1tch opened this issue Jan 24, 2021 · 2 comments
Closed

Unknown options are not passed into options #1445

CyberGl1tch opened this issue Jan 24, 2021 · 2 comments

Comments

@CyberGl1tch
Copy link

I'm running into an issue when i use the .allowUnknownOption(true) .
As you have mentioned after version 5.0.0 all unknown options should passed into program.opts() json
the problem is that program.opts() json includes only the defined program.option() parameters

I want to iterate through all the unknown options but i dont know if this package cant support this action or if it's a bug with allowUnknownOption feature.

My current code:

program
    .requiredOption('-s, --src-ip <number>', 'Source ')
    .requiredOption('-mo, --model-input <path...>', 'small pizza size')
    .requiredOption('-o, --output <path...>', 'flavour of pizza')
    .allowUnknownOption(true)
    .allowExcessArguments(true);



program.parse(process.argv);


const options = program.opts();
console.log(options)
console.log(program.args)

The command i am using for testing is
node index.js --src-ip 1.1.1.1 --model-input Test a -o c:/users /json --testOption unknownOption

The output:

{
  srcIp: '1.1.1.1',
  modelInput: [ 'Test', 'a' ],
  output: [ 'c:/users', '/json' ]
}
[ '--testOption', 'unknownOption' ]
@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 25, 2021

The wording in the README added with Commander 7 says:

To have an unknown option treated as an ordinary command-argument and continue looking for options, use .allowUnknownOption().

The unknown options end up in program.args, not in program.opts(). Commander does not take a guess at how to interpret the unknown options.

Related issues: #609 #1278 #1357

@shadowspawn
Copy link
Collaborator

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

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