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 Apr 6, 2015
1 parent 0d5c3d6 commit fb50344
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 @@ -305,3 +305,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 fb50344

Please sign in to comment.