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
feat: implement conflicts() for defining mutually exclusive arguments #741
Conversation
Addresses #534. Basic implementation of mutually exclusive arguments option, so if the user supplies both arguments the command fails. The new option is implemented with the signature: `.conflicts(key1, key2)` This adds a new message `Arguments %s and %s are mutually exclusive` and it's pt and pt-br translations.
Supports passing both arguments as strings, as arrarys or only an array.
@madcampos this is slated to go out with the next release of yargs, I would love the extra help testing:
Thanks for your contribution! |
|
||
Given the key `x` is set, the key `y` must not be set. | ||
|
||
Optionally `.conflicts()` can accept an object specifying multiple conflicting keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we give an example of how this might work, even like so .conflicts({ 'c': 'a', 's': 't'})
, or nah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh woops! i am sorry! i didn't refresh yesterday's page to see if you merged this; ignore me :D
Will do as soon as possible. 😉
|
@madcampos I was exited to use this new feature but it doesn't seem to work with dot-notations? Is this intentionally left out or should it be possible to implement?
|
Sorry, didn't have this case in mind... |
Is it possible to implement it in a way where one key could conflict with many keys. .conflicts('foo', ['bar', 'baz'])
//or
.conflicts({'foo': ['bar', 'baz']}) Great work on this btw. :D |
Sorry for the long due feedback… I could not fined a easy and performant object mapper/flattener so it became a problem. |
This pull request sees @madcampos' hard work over the finish line 🎉
I've made a few minor changes to make the
conflicts()
api almost identical to its cousinimplies()
.