Skip to content

Commit

Permalink
add a helper to annotate a flag as 'required' by a command
Browse files Browse the repository at this point in the history
  • Loading branch information
eparis committed Mar 17, 2015
1 parent 10c0e6d commit 9d6aada
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bash_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,16 @@ func (cmd *Command)GenCompletion(out *bytes.Buffer) {
gen(cmd, out)
postscript(out, cmd.Name())
}

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
}

0 comments on commit 9d6aada

Please sign in to comment.