mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Make the filename extension bit of docs easier to read.
This commit is contained in:
parent
787b737b48
commit
48b95d0594
1 changed files with 9 additions and 6 deletions
|
@ -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.
|
||||
|
||||
```go
|
||||
annotations := make([]string, 3)
|
||||
annotations[0] = "json"
|
||||
annotations[1] = "yaml"
|
||||
annotations[2] = "yml"
|
||||
|
||||
annotations := []string{"json", "yaml", "yml"}
|
||||
annotation := make(map[string][]string)
|
||||
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)
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue