aboutsummaryrefslogtreecommitdiffhomepage
path: root/command/help.go
diff options
context:
space:
mode:
Diffstat (limited to 'command/help.go')
-rw-r--r--command/help.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/command/help.go b/command/help.go
index cb22ce50..5bf58f6a 100644
--- a/command/help.go
+++ b/command/help.go
@@ -1,6 +1,7 @@
package command
import (
+ "bytes"
"errors"
"fmt"
"io"
@@ -13,14 +14,31 @@ var ErrHelp = errors.New("help requested")
func (n *node) PrintHelp() { _ = n.writeHelp() }
func (n *node) writeHelp() error {
+ prefix := strings.Join(append(n.prefix, n.name), " ")
+ var buf strings.Builder
+ offset := 7 + len(prefix)
+ line := offset + 14
+ w := bytes.Repeat([]byte{' '}, offset+1)
+ w[0] = '\n'
+
+ for _, flag := range n.suffix {
+ line += len(flag) + 1
+ if line >= 80 {
+ line = offset + len(flag) + 1
+ buf.Write(w)
+ }
+ buf.WriteByte(' ')
+ buf.WriteString(flag)
+ }
+
if _, err := fmt.Fprintf(n.out,
- "\nUsage:\t%s [-h | --help]%s COMMAND [OPTIONS]\n",
- strings.Join(append(n.prefix, n.name), " "), &n.suffix,
+ "usage: %s [-h | --help]%s <command> [<args>]\n",
+ prefix, &buf,
); err != nil {
return err
}
if n.child != nil {
- if _, err := fmt.Fprint(n.out, "\nCommands:\n"); err != nil {
+ if _, err := fmt.Fprint(n.out, "\ncommands:\n"); err != nil {
return err
}
}