-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
The argparse command should have an option to skip over unknown options #5367
Comments
Yes, it should. I had mentioned this in #4226. For completions it's nice because it allows us to just ignore uninteresting options entirely. However, this will break if there's an unknown option that requires an argument. So I'm not sure if we should call it "ignore-unknown" or "assume-bool" or something, to make clear that it can't really work with those. This particular case here: # but not when there are others
argparse 'a=+' 'b=+' 'c=+' -- -a alpha -b bravo -c charlie -t tango
# > Unknown option '-t' The "-t" can only be assumed to be a boolean option (i.e. like "t", not "t=+"), so the "tango" would remain in $argv. |
Yes, I agree completely. |
The solution I went with was to keep all unknown options in $argv (in the correct order, which meant disabling getopt's reordering!). That's the most flexible because it allows you to deal with them later. The alternative, to remove all unknown options, seems mostly useless. |
@faho Any idea when this will be in a release? I could use this for a script I'm working on. |
@lesderid It'll be in 3.1.0, which doesn't have a due date yet. I'd guess it'll come out in a month or two, but that depends on some of the kinks introduced by some refactoring being ironed out quickly enough. |
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:
Currently, in places where I would love to use
argparse
, I find myself picking apart$argv
in a loop or usingstring match
magic to regex my way through the problem. While that's workable, it feels like it's a deficiency inargparse
, 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.The text was updated successfully, but these errors were encountered: