pflag
pflag copied to clipboard
not a superset of flag: missing Func()
As of Go 1.16, base "flag" now has:
func (f *FlagSet) Func(name, usage string, fn func(string) error)`
Please add for feature parity -- Func()
is probably the best thing about the base "flag" package
Agreed. This one is missing. Hope they'll add this.
Does anyone have a temporary workaround?
As a workaround you can use go's flag parser:
fs := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
goflag.Func("flagname", "help message for flagname", func(string) error {
fmt.Println("functioning")
return nil
})
fs.AddGoFlagSet(goflag.CommandLine)
fs.Parse([]string{"--flagname", "123"})