forked from boot2docker/boot2docker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
90 lines (83 loc) · 1.88 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"os"
)
// The following vars will be injected during the build process.
var (
Version string
GitSHA string
)
type unknownCommandError struct {
cmd string
}
func (e unknownCommandError) Error() string {
return fmt.Sprintf("Unknown command: %s", e.cmd)
}
func main() {
// os.Exit will terminate the program at the place of call without running
// any deferred cleanup statements. It might cause unintended effects. To
// be safe, we wrap the program in run() and only os.Exit() outside the
// wrapper. Be careful not to indirectly trigger os.Exit() in the program,
// notably via log.Fatal() and on flag.Parse() where the default behavior
// is ExitOnError.
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "error in run: %v\n", err)
if _, ok := err.(unknownCommandError); ok {
usageShort()
}
os.Exit(1)
}
}
// Run the program and return exit code.
func run() error {
flags, err := config()
if err != nil {
return fmt.Errorf("config error: %v\n", err)
}
switch cmd := flags.Arg(0); cmd {
case "download":
return cmdDownload()
case "config", "cfg":
return cmdConfig()
case "init":
return cmdInit()
case "up", "start", "boot", "resume":
return cmdUp()
case "save", "suspend":
return cmdSave()
case "down", "halt", "stop":
return cmdStop()
case "poweroff":
return cmdPoweroff()
case "restart":
return cmdRestart()
case "reset":
return cmdReset()
case "delete", "destroy":
return cmdDelete()
case "info":
return cmdInfo()
case "shellinit", "socket":
return cmdShellInit()
case "status":
return cmdStatus()
case "ssh":
return cmdSSH()
case "ip":
return cmdIP()
case "upgrade":
return cmdUpgrade()
case "version":
// Version is now printed by the call to config()
return nil
case "help":
flags.Usage()
return nil
case "":
usageShort()
return nil
default:
return unknownCommandError{cmd: cmd}
}
}