This repository has been archived by the owner on Sep 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
help.go
67 lines (56 loc) · 1.1 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
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"log"
"os"
)
var cmdVersion = &Command{
Run: runVersion,
Usage: "version",
Short: "show version",
Long: `Shows the version string.`,
ApiUrl: "",
}
func runVersion(cmd *Command, args []string) {
log.Println(Version)
}
var cmdHelp = &Command{
Usage: "help [command]",
Short: "show help",
Long: `Help shows usage for a command.`,
}
func init() {
cmdHelp.Run = runHelp
}
func runHelp(cmd *Command, args []string) {
if len(args) == 0 {
printUsage()
return
}
if len(args) != 1 {
log.Fatal("too many arguments")
}
for _, cmd := range commands {
if cmd.Name() == args[0] {
cmd.printUsage()
return
}
}
fmt.Fprintf(os.Stderr, "Unknown help topic: %s\n\n", args[0])
os.Exit(2)
}
func printUsage() {
fmt.Printf("Usage: es <command> [options] [arguments]\n\n")
fmt.Printf("Supported commands are:\n\n")
for _, cmd := range commands {
if cmd.Short != "" {
fmt.Printf(" %-16s %s\n", cmd.Name(), cmd.Short)
}
}
fmt.Println()
fmt.Println("See 'es help [command]' for more information about a command.")
}
func usage() {
printUsage()
os.Exit(2)
}