-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd_help.go
48 lines (43 loc) · 821 Bytes
/
cmd_help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"bytes"
"fmt"
"github.com/wsxiaoys/terminal/color"
)
// add space to line up
func Ljust(word string, length int) string {
if len(word) > length {
return word
} else {
var buffer bytes.Buffer
l := length - len(word)
buffer.WriteString(word)
for i := 0; l > i; i++ {
buffer.WriteString(" ")
}
return buffer.String()
}
}
var CmdHelp = &Cmd{
Name: "help",
Desc: "show help.",
Fn: func(args []string) error {
color.Printf(`@{g}erk@{|} inline issue manager
v%s
Usage: erk commands are:
`, VERSION)
maxLen := func() int {
max := 0
for _, cmd := range CmdList {
if max < len(cmd.Name) {
max = len(cmd.Name)
}
}
return max
}()
for _, cmd := range CmdList {
fmt.Printf(" "+Ljust(cmd.Name, maxLen)+" %s\n", cmd.Desc)
}
return nil
},
}