forked from mirror/cobra
Merge pull request #106 from eparis/bash-comp-docs
Make the filename extension bit of docs easier to read.
This commit is contained in:
commit
743fa31b46
|
@ -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 New Issue