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

Multiple enhancement requests: Validation #30

Open
ilyavolodin opened this issue Feb 13, 2019 · 2 comments
Open

Multiple enhancement requests: Validation #30

ilyavolodin opened this issue Feb 13, 2019 · 2 comments

Comments

@ilyavolodin
Copy link

ilyavolodin commented Feb 13, 2019

I was going through ESLint configuration for optionator and wanted to enhance validation a bit, and ran into a few limitations:

Exclusive options

Currently it's possible to setup mutuallyExclusive options, however, it's really tough to mark a given option as fully exclusive (as in, doesn't work with any other option). In ESLint configuration, such options would be --init and --help.
It would also be nice to mark an option exclusive for anything other then _ input. An example of such option in ESLint would be --print-config [file].

DependsOn with a value

Currently dependsOn can only specify the name of the option that is required to have any value. I would like to be able to require a specific value. For example, --ignore option in ESLint has a default of true, and --ignore-file only makes sense when it is true, but if --ignore is set to false, --ignore-file doesn't make any sense any more. Currently it's not possible to set this up.

Ability to dependOn _ option

A lot of options in ESLint only make sense if the user provided a file or a glob. As far as I can tell, there's no way to depend on that right now.

Ability to specify error message for validation error

I would like to mark some options mutuallyExclusive, but provide a better error message when two or more of those options are used. I understand that current array of array format doesn't leave much space for custom error messages, so maybe another format can be introduced side-by-side? Or as a last resort, when optionator.parse throws, could error object include all of the options that were used with their values? That would at least allow to intercept errors and specify a better message. Would be nice to be able to specify custom error message for dependsOn as well. Currently it only says that requirements were not met, without explaining those requirements at all.

@nvuillam
Copy link

dependsOn with value would also be interesting for me :)

@Kurt-von-Laven
Copy link

It would also be helpful to have sort of the opposite of dependsOn _, so that a named argument could be mutually exclusive with a positional argument (or with all positional arguments). An example use case would be specifying a --path to a directory vs. a list of files.

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

3 participants