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

Error in the check for option name clash function in 6.0.0 #1308

Closed
jceloi opened this issue Jul 20, 2020 · 5 comments
Closed

Error in the check for option name clash function in 6.0.0 #1308

jceloi opened this issue Jul 20, 2020 · 5 comments

Comments

@jceloi
Copy link

jceloi commented Jul 20, 2020

It seems to me that there is a bug in the new name clash feature. I do have a clash where there should be no.
I've added some logs to get inputs :

_checkForOptionNameClash :
Option : {"flags":"--opts ","required":true,"optional":false,"variadic":false,"mandatory":false,"long":"--opts","negate":false,"description":"specify opts path"}

Current this.options does not contain '--no-opts' -> this._findOption(negativeLongFlag) returns 'undefined'
!undefined -> foundClash = true -> throws 'Error: option 'opts' clashes with existing property 'opts' on Command'

So there is a clash whereas neither the positive no the negative option does exist.
Am I missing something ? It seems to be problematic to me.

@shadowspawn
Copy link
Collaborator

The Command object has a method called .opts() which is what your --opts is clashing with.

const { program } = require('commander');
program.storeOptionsAsProperties(true); // To suppress new exception and demonstrate problem

program
  .option('--opts <value>');
program.parse();

console.log(program.opts);
console.log(program.opts());
$ node index.js 
[Function: opts]
{ opts: [Function: opts] }

$ node index.js --opts value
value
/Users/john/Documents/Sandpits/commander/issues/1308/index.js:9
console.log(program.opts());
                    ^

TypeError: program.opts is not a function
... stack

@jceloi
Copy link
Author

jceloi commented Jul 20, 2020

Hello @shadowspawn , thanks for the answer, I do get now why I had something not undefined here line 451 and I got confused on the code's intent on line 464.

Just to get with a little more context : the module using Commander and providing it with an 'opts' parameter is mocha-isolation https://www.npmjs.com/package/mocha-isolation

@shadowspawn
Copy link
Collaborator

Interesting. The deprecated mocha-isolation is likely to break! It is using any version of Commander:

  "dependencies": {
    "colors": "*",
    "commander": "*",
    "mocha": "*"
  },

And in addition is using the global Command, so won't play well with other parts of program using Commander:

const program = require('commander');

@shadowspawn
Copy link
Collaborator

The new clash error is going to get hit when people upgrade with existing clashes that they didn't know about or worked around. We can try and improve the message if other people are confused too.

@shadowspawn
Copy link
Collaborator

An answer was provided, and it hasn't come up again in a month. Closing 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