@@ -23,9 +23,9 @@ import (
23
23
)
24
24
25
25
const (
26
- requiredAsGroup = "cobra_annotation_required_if_others_set"
27
- oneRequired = "cobra_annotation_one_required"
28
- mutuallyExclusive = "cobra_annotation_mutually_exclusive"
26
+ requiredAsGroupAnnotation = "cobra_annotation_required_if_others_set"
27
+ oneRequiredAnnotation = "cobra_annotation_one_required"
28
+ mutuallyExclusiveAnnotation = "cobra_annotation_mutually_exclusive"
29
29
)
30
30
31
31
// MarkFlagsRequiredTogether marks the given flags with annotations so that Cobra errors
@@ -37,7 +37,7 @@ func (c *Command) MarkFlagsRequiredTogether(flagNames ...string) {
37
37
if f == nil {
38
38
panic (fmt .Sprintf ("Failed to find flag %q and mark it as being required in a flag group" , v ))
39
39
}
40
- if err := c .Flags ().SetAnnotation (v , requiredAsGroup , append (f .Annotations [requiredAsGroup ], strings .Join (flagNames , " " ))); err != nil {
40
+ if err := c .Flags ().SetAnnotation (v , requiredAsGroupAnnotation , append (f .Annotations [requiredAsGroupAnnotation ], strings .Join (flagNames , " " ))); err != nil {
41
41
// Only errs if the flag isn't found.
42
42
panic (err )
43
43
}
@@ -53,7 +53,7 @@ func (c *Command) MarkFlagsOneRequired(flagNames ...string) {
53
53
if f == nil {
54
54
panic (fmt .Sprintf ("Failed to find flag %q and mark it as being in a one-required flag group" , v ))
55
55
}
56
- if err := c .Flags ().SetAnnotation (v , oneRequired , append (f .Annotations [oneRequired ], strings .Join (flagNames , " " ))); err != nil {
56
+ if err := c .Flags ().SetAnnotation (v , oneRequiredAnnotation , append (f .Annotations [oneRequiredAnnotation ], strings .Join (flagNames , " " ))); err != nil {
57
57
// Only errs if the flag isn't found.
58
58
panic (err )
59
59
}
@@ -70,7 +70,7 @@ func (c *Command) MarkFlagsMutuallyExclusive(flagNames ...string) {
70
70
panic (fmt .Sprintf ("Failed to find flag %q and mark it as being in a mutually exclusive flag group" , v ))
71
71
}
72
72
// Each time this is called is a single new entry; this allows it to be a member of multiple groups if needed.
73
- if err := c .Flags ().SetAnnotation (v , mutuallyExclusive , append (f .Annotations [mutuallyExclusive ], strings .Join (flagNames , " " ))); err != nil {
73
+ if err := c .Flags ().SetAnnotation (v , mutuallyExclusiveAnnotation , append (f .Annotations [mutuallyExclusiveAnnotation ], strings .Join (flagNames , " " ))); err != nil {
74
74
panic (err )
75
75
}
76
76
}
@@ -91,9 +91,9 @@ func (c *Command) ValidateFlagGroups() error {
91
91
oneRequiredGroupStatus := map [string ]map [string ]bool {}
92
92
mutuallyExclusiveGroupStatus := map [string ]map [string ]bool {}
93
93
flags .VisitAll (func (pflag * flag.Flag ) {
94
- processFlagForGroupAnnotation (flags , pflag , requiredAsGroup , groupStatus )
95
- processFlagForGroupAnnotation (flags , pflag , oneRequired , oneRequiredGroupStatus )
96
- processFlagForGroupAnnotation (flags , pflag , mutuallyExclusive , mutuallyExclusiveGroupStatus )
94
+ processFlagForGroupAnnotation (flags , pflag , requiredAsGroupAnnotation , groupStatus )
95
+ processFlagForGroupAnnotation (flags , pflag , oneRequiredAnnotation , oneRequiredGroupStatus )
96
+ processFlagForGroupAnnotation (flags , pflag , mutuallyExclusiveAnnotation , mutuallyExclusiveGroupStatus )
97
97
})
98
98
99
99
if err := validateRequiredFlagGroups (groupStatus ); err != nil {
@@ -232,9 +232,9 @@ func (c *Command) enforceFlagGroupsForCompletion() {
232
232
oneRequiredGroupStatus := map [string ]map [string ]bool {}
233
233
mutuallyExclusiveGroupStatus := map [string ]map [string ]bool {}
234
234
c .Flags ().VisitAll (func (pflag * flag.Flag ) {
235
- processFlagForGroupAnnotation (flags , pflag , requiredAsGroup , groupStatus )
236
- processFlagForGroupAnnotation (flags , pflag , oneRequired , oneRequiredGroupStatus )
237
- processFlagForGroupAnnotation (flags , pflag , mutuallyExclusive , mutuallyExclusiveGroupStatus )
235
+ processFlagForGroupAnnotation (flags , pflag , requiredAsGroupAnnotation , groupStatus )
236
+ processFlagForGroupAnnotation (flags , pflag , oneRequiredAnnotation , oneRequiredGroupStatus )
237
+ processFlagForGroupAnnotation (flags , pflag , mutuallyExclusiveAnnotation , mutuallyExclusiveGroupStatus )
238
238
})
239
239
240
240
// If a flag that is part of a group is present, we make all the other flags
0 commit comments