Skip to content

Commit d24d87a

Browse files
Stebalienhannahhoward
authored andcommitted
help: wrap subcommand help text
1 parent 70ca134 commit d24d87a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cli/helptext.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
180180
fields.Options = strings.Join(optionText(width, cmd), "\n")
181181
}
182182
if len(fields.Subcommands) == 0 {
183-
fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n")
183+
fields.Subcommands = strings.Join(subcommandText(width, cmd, rootName, path), "\n")
184184
}
185185
if len(fields.Synopsis) == 0 {
186186
fields.Synopsis = generateSynopsis(width, cmd, pathStr)
@@ -228,7 +228,7 @@ func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer
228228

229229
// autogen fields that are empty
230230
if len(fields.Subcommands) == 0 {
231-
fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n")
231+
fields.Subcommands = strings.Join(subcommandText(width, cmd, rootName, path), "\n")
232232
}
233233
if len(fields.Synopsis) == 0 {
234234
fields.Synopsis = generateSynopsis(width, cmd, pathStr)
@@ -385,7 +385,7 @@ func optionText(width int, cmd ...*cmds.Command) []string {
385385
return lines
386386
}
387387

388-
func subcommandText(cmd *cmds.Command, rootName string, path []string) []string {
388+
func subcommandText(width int, cmd *cmds.Command, rootName string, path []string) []string {
389389
prefix := fmt.Sprintf("%v %v", rootName, strings.Join(path, " "))
390390
if len(path) > 0 {
391391
prefix += " "
@@ -414,7 +414,8 @@ func subcommandText(cmd *cmds.Command, rootName string, path []string) []string
414414

415415
lines = align(lines)
416416
for i, sub := range subcmds {
417-
lines[i] += " - " + sub.Helptext.Tagline
417+
lines[i] += " - "
418+
lines[i] = appendWrapped(lines[i], sub.Helptext.Tagline, width)
418419
}
419420

420421
return lines

0 commit comments

Comments
 (0)