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

Cannot write .conflicts("option-name"); we should write like .conflicts("optionName") ? #1796

Closed
wataash opened this issue Sep 4, 2022 · 5 comments

Comments

@wataash
Copy link

wataash commented Sep 4, 2022

// this is INVALID
program
  .addOption(new Option('--option-a').conflicts('option-b'))
  .addOption(new Option('--option-b'))

// this works
program
  .addOption(new Option('--option-a').conflicts('optionB'))
  .addOption(new Option('--option-b'))

Is it intended design? I think .conflicts('option-b')) is natural.

@wataash
Copy link
Author

wataash commented Sep 4, 2022

And I think giving the leading hyphens (.conflicts('--option-b'))) is also natural, should be accepted.

@shadowspawn
Copy link
Collaborator

Reasonable question. This is intended design, the conflicting option is identified by the camelCase option name. This is the same pattern used with the other routines passed an option identifier, like .getOptionValue().

This is not mentioned in the README but is included in the example file: https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js

( Supporting the option flags would lead to some additional questions. If you were allowed to use the long flag, would you also be allowed to use the short flag? Would you need to list both to cover both flags?)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Sep 4, 2022

I was actually thinking we might use raw option originally as the key, but when I saw camelCase used in the development of the feature I liked it much better.

#1678 (comment)

@wataash
Copy link
Author

wataash commented Sep 4, 2022

Thanks for the explanation!
Sorry, I didn't see the example file.
It's OK if it's the intended -- I just wondered this specification was just out of consideration.
I understood using camelCase is the consistent way in the commander API/implementation.

@wataash wataash closed this as completed Sep 4, 2022
@wataash
Copy link
Author

wataash commented Sep 4, 2022

If you were allowed to use the long flag, would you also be allowed to use the short flag? Would you need to list both to cover both flags?

At least Option('-v') should be identified as -v.

But, as you said, there's room for debate how to identify Option(' -v, --verbose ')...
Personally I prefer accepting all of these:

  • -v
  • --verbose
  • (SPACE)-v(SPACE)
  • (SPACE)-v , --verbose(SPACE)

because it's obvious that the user (developer) is trying to select the -v option. There's no other way to interpret.

UPDATE: I noticed it was not that simple when thinking about Option(-v, --verbose <count>) or any other style...

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