Collect unknown flags
Author: aphilasCreated Apr 23, 2025Updated Aug 16, 2026
Labelskind/featurestatus/waiting-for-responsearea/v4
Checklist
- Are you running the latest v3 release? The list of releases is here.
- Did you check the manual for your release? The v3 manual is here.
- Did you perform a search about this feature? Here's the GitHub guide about searching.
What problem does this solve?
it's often desirable to create a wrapper around an existing command
in this case while -- is canonical (#2072), in some cases you want the usage to be transparent.
Solution description
allow and collect unknown flags
optionally, allow interspersing known an unknown flags
prior art
- in kong you can use
passthroughto stop flag processing and pass all subsequent flags/args to a[]string
var CLI struct {
Flag string `short:"f"`
Args []string `arg:"" optional:"" passthrough:""`
}
// use CLI.Flag
// Execute desired command
exec.Command(cmd, CLI.Args...)mycli -f foo --uknown-flag unknown-arg- in spf13/pflag and hence cobra, you can ignore unknown flags, but the pr to collect these flags is still open - https://github.com/spf13/pflag/pull/199
justification
i believe this is not a niche requirement, and some clis may need to accept unknown args and pass them to another program
the simplest case is time ls -a
a different case would be something like helmx --custom-flag get all
see more use cases here: https://github.com/spf13/cobra/issues/739
Describe alternatives you've considered
- using
--
possibly related to #144
N.B. this is not a complete feature request, as i have not accurately defined the desired semantics, but would love for comments
Source: urfave/cli