mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
add a helper to annotate a flag as 'required' by a command
This commit is contained in:
parent
9b2e6822e5
commit
a068307565
1 changed files with 13 additions and 0 deletions
|
@ -328,3 +328,16 @@ func (cmd *Command) GenBashCompletionFile(filename string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd *Command) MarkFlagRequired(name string) {
|
||||||
|
flag := cmd.Flags().Lookup(name)
|
||||||
|
if flag == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if flag.Annotations == nil {
|
||||||
|
flag.Annotations = make(map[string][]string)
|
||||||
|
}
|
||||||
|
annotation := make([]string, 1)
|
||||||
|
annotation[0] = "true"
|
||||||
|
flag.Annotations[BashCompOneRequiredFlag] = annotation
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue