-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I have a small feature request.
When using the argparse fish builtin command, you are required to define all the possible options you'll be receiving before hand, and cannot cherry pick the options you care about and then just ignore the rest. I have found that I frequently don't care about all the options being passed to my script - I just want to parse what I have defined and skip over the rest, or handle the remaining elsewhere. This is especially useful if you are wrapping other functionality or farming off small bits of processing to other functions.
I propose adding an -i/--ignore-missing or -u/--skip-undefined flag to parse what we can and skip the rest.
Example:
# works great when I know about all the flags (-a,-b,-c)
argparse 'a=+' 'b=+' 'c=+' -- -a alpha -b bravo -c charlie
# but not when there are others
argparse 'a=+' 'b=+' 'c=+' -- -a alpha -b bravo -c charlie -t tango
# > Unknown option '-t'
# proposing a -i/--ignore-missing flag
argparse --ignore-missing 'a=+' 'b=+' 'c=+' -- -a alpha -b bravo -c charlie -t tango
# $_flag_a, $_flag_b, $_flag_c are set
# $_flag_t wasn't defined, so it is not...Currently, in places where I would love to use argparse, I find myself picking apart $argv in a loop or using string match magic to regex my way through the problem. While that's workable, it feels like it's a deficiency in argparse, which really should be the one best way to handle command arguments.
Note: I looked into the -s/--stop-nonopt option, but it only concerns itself with arguments and not flags, and isn't really the behavior I am describing.