From 9d6aadae0e0ce4b21a837b99d3779da9530a1622 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 1c92d3382..0a661a57e 100644 --- a/bash_completions.go +++ b/bash_completions.go @@ -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 +}