Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit 2b84834

Browse files
committed
Use tabwriter in commands help section
1 parent 610063a commit 2b84834

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

help.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"io"
7+
"text/tabwriter"
78
"unicode/utf8"
89
)
910

@@ -49,12 +50,21 @@ func renderHelp(cmd Command, fl *flag.FlagSet, w io.Writer) {
4950
fmt.Fprintf(w, "\n")
5051
fmt.Fprint(w, "Commands:\n")
5152
}
53+
54+
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', tabwriter.StripEscape)
5255
for _, cmd := range pc.Subcommands() {
5356
if cmd.Spec().Hidden {
5457
continue
5558
}
5659

57-
fmt.Fprintf(w, "\t%v\t%v\n", cmd.Spec().Name, cmd.Spec().ShortDesc())
60+
// \xFF is used to escape the leading \t so tabwriter ignores it
61+
fmt.Fprintf(tw,
62+
"\xFF\t\xFF%v\t%v\n",
63+
cmd.Spec().Name,
64+
cmd.Spec().ShortDesc(),
65+
)
5866
}
67+
68+
tw.Flush()
5969
}
6070
}

0 commit comments

Comments
 (0)