From a0683075651a3be2278b97f2f2e34db506afd85a Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Tue, 17 Mar 2015 15:14:06 -0400 Subject: [PATCH] add a helper to annotate a flag as 'required' by a command --- bash_completions.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bash_completions.go b/bash_completions.go index f9006da6..1c564074 100644 --- a/bash_completions.go +++ b/bash_completions.go @@ -328,3 +328,16 @@ func (cmd *Command) GenBashCompletionFile(filename string) error { } 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 +}