Skip to content

Commit b647969

Browse files
committed
Small refactor in cmd flag docs generation
Just a little cleanup I wanted to do after creating the previous commit. Note that f.Deprecated and f.ShorthandDeprecated are both strings so that's why I think we can just compare to "" rather than use len(..) == 0, and also why I think we can skip the extra len > 0 check.
1 parent a2bafee commit b647969

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

  • internal/documentation/asciidoc/cli

internal/documentation/asciidoc/cli/cli.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,26 @@ func options(flags *pflag.FlagSet) []option {
129129
var result []option
130130

131131
flags.VisitAll(func(flag *pflag.Flag) {
132-
if !(len(flag.ShorthandDeprecated) > 0) && len(flag.Shorthand) > 0 {
133-
opt := option{
134-
flag.Name,
135-
flag.Shorthand,
136-
flagDefValueMaybe(flag),
137-
flag.Usage,
138-
}
139-
result = append(result, opt)
140-
} else {
141-
opt := option{
142-
Name: flag.Name,
143-
DefaultValue: flagDefValueMaybe(flag),
144-
Usage: flag.Usage,
145-
}
146-
result = append(result, opt)
132+
opt := option{
133+
flag.Name,
134+
flagShortHandMaybe(flag),
135+
flagDefValueMaybe(flag),
136+
flag.Usage,
147137
}
138+
result = append(result, opt)
148139
})
149140

150141
return result
151142
}
152143

144+
func flagShortHandMaybe(flag *pflag.Flag) string {
145+
if flag.ShorthandDeprecated != "" {
146+
// Don't show deprecated flag shorthand in the docs
147+
return ""
148+
}
149+
return flag.Shorthand
150+
}
151+
153152
func flagDefValueMaybe(flag *pflag.Flag) string {
154153
// For `ec opa test` the default value for the --parallel flag is `runtime.NumCPU()`.
155154
// We don't want to show that in the docs since it causes problems in the CI and it

0 commit comments

Comments
 (0)