spf13 / pflag

Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
BSD 3-Clause "New" or "Revised" License
2.43k stars 348 forks source link

Preserve unknown flags #337

Open ikedam opened 2 years ago

ikedam commented 2 years ago

FlagSet.ParseErrorsWhitelist.UnknownFlags ignores unknown flags, but throws away them. I want pflag just skip them and pass them to Args().

Input:

--known-flag known-flag-value --unknown-flag arg0 arg1 arg2

Current output via Args():

arg1 arg2

arg0 is treated as value for unknown-flag-value

Wanted output via Args():

--unknown-flag arg0 arg1 arg2

Background: I want to create a utility wrapper for existing command. It accepts extra flags and change how to call the command. It's used like this:

mygrep --my-extra-flag1 --my-extra-flag2 my-extra-flag2-value -i -e search-text file1 file2
nhatthm commented 2 years ago

This is a nice-to-have feature. I'm wondering why no one is reviewing this