-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelp.go
More file actions
81 lines (58 loc) · 1.45 KB
/
Copy pathhelp.go
File metadata and controls
81 lines (58 loc) · 1.45 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package stdcli
import (
"fmt"
"sort"
)
func Help(c *Context) error {
helpGlobal(c.engine)
return nil
}
func helpGlobal(e *Engine) {
cs := []Command{}
for _, cmd := range e.Commands {
if cmd.Invisible {
continue
}
cs = append(cs, cmd)
}
sort.Slice(cs, func(i, j int) bool { return cs[i].FullCommand() < cs[j].FullCommand() })
l := 7
for _, cmd := range cs {
c := cmd.FullCommand()
if len(c) > l {
l = len(c)
}
}
// e.Writer.Writef(fmt.Sprintf(fmt.Sprintf("<h2>%%-%ds</h2> <h2>%%s</h2>\n", l), "COMMAND", "DESCRIPTION"))
for _, cmd := range cs {
e.Writer.Writef(fmt.Sprintf(fmt.Sprintf("<h1>%%-%ds</h1> <value>%%s</value>\n", l), cmd.FullCommand(), cmd.Description))
}
}
func helpCommand(e *Engine, cmd *Command) {
e.Writer.Writef("<h2>USAGE</h2>\n <value>%s</value> <info>%s</info>\n\n", cmd.FullCommand(), cmd.Usage)
e.Writer.Writef("<h2>DESCRIPTION</h2>\n <value>%s</value>\n\n", cmd.Description)
e.Writer.Writef("<h2>OPTIONS</h2>\n")
ll := 0
ls := 0
fs := []Flag{}
for _, f := range cmd.Flags {
if f.SkipHelpCommand {
continue
}
fs = append(fs, f)
}
sort.Slice(fs, func(i, j int) bool { return fs[i].Name < fs[j].Name })
for _, f := range fs {
l := f.UsageLong()
s := f.UsageShort()
if len(l) > ll {
ll = len(l)
}
if len(s) > ls {
ls = len(s)
}
}
for _, f := range fs {
e.Writer.Writef(fmt.Sprintf(fmt.Sprintf(" %%-%ds %%-%ds\n", ll, ls), f.UsageLong(), f.UsageShort()))
}
}