sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

Proposal: fail on extraneous flags #126

Closed gtarsia closed 3 years ago

gtarsia commented 4 years ago

Running git -q results in:

unknown option: -q
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

I think that is a good feature because it prevents the user from fat fingering.

Regarding property name, it could be called allowExtraneous, just extraneous or something else.

I would go as far as defaulting it to false, but I guess that would require a major release, let alone an acceptance of this feature.

EDIT: I can provide PR with tests.

LitoMore commented 4 years ago

I think that's too much. I would like make this package more simpler.

You could make a new package to handle this feature.

Something like this:

const meow = require('meow');
const meowExtraneous = require('meow-extraneous');

const cli = meow();

// Do parameter validation
meowExtraneous(cli);
sindresorhus commented 4 years ago

@zzyyxxww I like it. I would call it allowExtraneousFlags, or maybe allowUnknownFlags? I agree, it should be false by default.

PR welcome :)

gtarsia commented 4 years ago

@sindresorhus if anyone else wants to do this, good, I won't because I thought it would be trivial, but for every flag --no-<flag> is also a valid flag, and I don't quite know or want to know how to deal with the edge cases for different types

kristian commented 3 years ago

Thanks @weareoutman, @sindresorhus is the pull request of @weareoutman something you would consider merging? Thanks!