pflag
pflag copied to clipboard
Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
Code Example: ```go package main import ( "fmt" "github.com/spf13/pflag" ) func main() { fs := pflag.NewFlagSet("test", pflag.PanicOnError) fs.StringToString("testflag", map[string]string{}, "") fs.Set("testflag", "x=[]") fmt.Println(fs.Lookup("testflag").Value.String()) result, _ := fs.GetStringToString("testflag") fmt.Println(result) } ```...
minimal repro code: ``` package main import ( "fmt" "github.com/spf13/cobra" ) var ( name string count int enabled bool ) var cmd = &cobra.Command{ Use: "test", RunE: func(cmd *cobra.Command, args...
The `defaultIsZeroValue` function does not check on the `DefValue` field, for generic `Value` types., but instead wrongly checks on the flag `Value` field. This results in the help screen wrongly...
Currently it is possible to ignore unknown flags (with `FlagSet.ParseErrorsWhitelist.UnknownFlags`) but there is no way to find out what they were after the fact. Add a method which registers a...
``` package main import ( "fmt" "github.com/spf13/pflag" ) func main() { var myArray []string pflag.StringArrayVar(&myArray, "array", []string{}, "List of strings") pflag.Parse() fmt.Printf("Array length: %d\n", len(myArray)) fmt.Printf("Array contents: %v\n", myArray) }...
StringP flag doesn't check if next value -s another option. ``` package main import ( "fmt" "github.com/spf13/cobra" "os" ) func main() { // Create the root command var rootCmd =...
When `FlagSet::ParseErrorsWhitelist.UnknownFlags = true` unknown flags are thrown away. I propose adding a map of `UnknownFlags` to `FlagSet` which is populated when the option (above) is set The map would...
This revision tweaks the internals of the StringToString flag type to ensure that pointers are consistent across invocations of FlagSet.Parse(), Flag.Set(), FlagSet.GetStringToString(). Prior to this change, each call to GetStringToString...
- relates to https://github.com/docker/cli/pull/6714 The SetAnnotation method returns an error if the given flag does not exist. While handling the error should normally be the recommendation, in many cases the...