pflag icon indicating copy to clipboard operation
pflag copied to clipboard

Add `PassUnknownFlagsToArgs` to allow get unknown flags via `Args()`

Open ikedam opened this issue 3 years ago • 2 comments

Close #337

FlagSet.ParseErrorsWhitelist.UnknownFlags=true behaves like this:

  • Input:
    -xayb -c -z --known-flag known-flag-value --unknown-flag arg0 arg1 arg2
    
    • -x, -y, -z and --unknown-flag are unknown
  • Args():
    arg1 arg2
    

This request adds FlagSet.ParseErrorsWhitelist.PassUnknownFlagsToArgs, and setting it to true results following behavior:

  • Args() with FlagSet.ParseErrorsWhitelist.PassUnknownFlagsToArgs=true:
    -xy -z --unknown-flag arg0 arg1 arg2
    

Any unknown and unprocessed flags are passed to Args().

ikedam avatar Dec 11 '21 08:12 ikedam

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 11 '21 08:12 CLAassistant

@spf13 👋 Any chance of this landing? I have exactly this use-case as well :)

If it needs work, I would be happy to take it on

jippi avatar May 09 '23 09:05 jippi