-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelp.go
55 lines (51 loc) · 1.23 KB
/
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
49
50
51
52
53
54
55
package main
import (
"flag"
"fmt"
"os"
)
func init() {
register(&Command{
name: "help",
help: "Shows this help message, use [COMMAND] for command parameters",
handle: help,
})
}
func help() {
for _, command := range commands {
if command.name == flag.Arg(1) {
if len(command.params) > 0 {
fmt.Printf("%s [options] %s [param1=value1 param2=value2 ...]\n", os.Args[0], command.name)
} else {
fmt.Printf("%s [options] %s\n", os.Args[0], command.name)
}
fmt.Println("\nOptions:")
flag.PrintDefaults()
fmt.Println("\nDescription:\n ", command.help)
if len(command.params) > 0 {
fmt.Print("\nParameters: ")
for _, param := range command.params {
fmt.Printf("\n %-13s %s", param.name, param.desc)
if param.defval != "" {
fmt.Printf(", default value: %s", param.defval)
}
}
}
fmt.Printf("\n\n")
return
}
}
fmt.Printf("%s [options] command [param1=value1 param2=value2 ...]", os.Args[0])
fmt.Println("\nOptions:")
flag.PrintDefaults()
fmt.Println("\nCommands:")
group := ""
for _, cmd := range commands {
if cmd.group != group {
fmt.Printf("%s\n", cmd.group)
group = cmd.group
}
fmt.Printf(" %-15s - %s\n", cmd.name, cmd.help)
}
fmt.Println("")
}