Make the filename extension bit of docs easier to read.

This commit is contained in:
Eric Paris 2015-05-04 16:20:06 -04:00
parent 787b737b48
commit 48b95d0594

View file

@ -123,15 +123,18 @@ and you'll get something like
In this example we use --filename= and expect to get a json or yaml file as the argument. To make this easier we annotate the --filename flag with valid filename extensions. In this example we use --filename= and expect to get a json or yaml file as the argument. To make this easier we annotate the --filename flag with valid filename extensions.
```go ```go
annotations := make([]string, 3) annotations := []string{"json", "yaml", "yml"}
annotations[0] = "json"
annotations[1] = "yaml"
annotations[2] = "yml"
annotation := make(map[string][]string) annotation := make(map[string][]string)
annotation[cobra.BashCompFilenameExt] = annotations annotation[cobra.BashCompFilenameExt] = annotations
flag := &pflag.Flag{"filename", "f", usage, value, value.String(), false, annotation} flag := &pflag.Flag{
Name: "filename",
Shorthand: "f",
Usage: usage,
Value: value,
DefValue: value.String(),
Annotations: annotation,
}
cmd.Flags().AddFlag(flag) cmd.Flags().AddFlag(flag)
``` ```