Skip to content

Multiple enhancement requests: Validation #30

@ilyavolodin

Description

@ilyavolodin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions