Skip to content

Commit

Permalink
Fix noop if flags are empty and use Sprintfs
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
  • Loading branch information
saschagrunert committed Aug 6, 2019
1 parent 7b076eb commit 130d02f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions docs.go
Expand Up @@ -54,8 +54,6 @@ func (a *App) writeDocTemplate(w io.Writer) error {
})
}

const nl = "\n"

func prepareCommands(commands []Command, level int) []string {
coms := []string{}
for i := range commands {
Expand All @@ -73,9 +71,8 @@ func prepareCommands(commands []Command, level int) []string {

flags := prepareArgsWithValues(command.Flags)
if len(flags) > 0 {
prepared += nl
prepared += fmt.Sprintf("\n%s", strings.Join(flags, "\n"))
}
prepared += strings.Join(flags, nl)

coms = append(coms, prepared)

Expand Down Expand Up @@ -113,21 +110,21 @@ func prepareFlags(
modifiedArg += sep
}
if len(trimmed) > 1 {
modifiedArg += "--" + trimmed
modifiedArg += fmt.Sprintf("--%s", trimmed)
} else {
modifiedArg += "-" + trimmed
modifiedArg += fmt.Sprintf("-%s", trimmed)
}
}
modifiedArg += closer
if flag.TakesValue() {
modifiedArg += "=" + value
modifiedArg += fmt.Sprintf("=%s", value)
}

if addDetails {
modifiedArg += flagDetails(flag)
}

args = append(args, modifiedArg+nl)
args = append(args, modifiedArg+"\n")

}
sort.Strings(args)
Expand Down

0 comments on commit 130d02f

Please sign in to comment.