Skip to content

Commit

Permalink
(DOCSP-30039) Adds mutually exclusive flag info (#41)
Browse files Browse the repository at this point in the history
* (DOCSP-30039) Adds mutually exclusive flag info

* Moves variables inside if statement
  • Loading branch information
sarahsimpers authored Jul 10, 2023
1 parent 1a45994 commit d5a0eae
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@ func FlagUsages(f *pflag.FlagSet) string {
}
}

line += "\n - " + usage
if len(flag.Annotations["cobra_annotation_mutually_exclusive"]) != 0 {
mutuale := fmt.Sprintf("%v", flag.Annotations["cobra_annotation_mutually_exclusive"])
mutuale = strings.ReplaceAll(mutuale, "]", "")
mutuale = strings.ReplaceAll(mutuale, "[", "")
mutuale = strings.ReplaceAll(mutuale, flag.Name+" ", "")
mutuale = strings.ReplaceAll(mutuale, " "+flag.Name, "")
mutuale = strings.ReplaceAll(mutuale, " ", ", --")
line += "\n - " + usage + "\n\n Mutually exclusive with --" + mutuale + "."
} else {
line += "\n - " + usage
}
if !defaultIsZeroValue(flag) {
if flag.Value.Type() == stringType {
line += fmt.Sprintf(" This value defaults to %q.", flag.DefValue)
Expand Down

0 comments on commit d5a0eae

Please sign in to comment.