Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

The argparse command should have an option to skip over unknown options #5367

Copy link
Copy link

Description

@mattmc3
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.