forked from boot2docker/boot2docker-cli
/
main.go
105 lines (92 loc) · 2.73 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// This is the boot2docker management utilty.
package main
import (
"os"
// keep 3rd-party imports separate from stdlib with an empty line
flag "github.com/ogier/pflag"
)
// The following vars will be injected during the build process.
var (
Version string
GitSHA string
)
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().
os.Exit(run())
}
// Run the program and return exit code.
func run() int {
flag.Usage = usageLong // make "-h" work similarly to "help"
if err := config(); err != nil {
errf("%s\n", err)
return 1
}
switch cmd := flag.Arg(0); cmd {
case "download":
return cmdDownload()
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":
return cmdDelete()
case "info":
return cmdInfo()
case "status":
return cmdStatus()
case "ssh":
return cmdSSH()
case "version":
outf("Client version: %s\nGit commit: %s\n", Version, GitSHA)
return 0
case "help":
flag.Usage()
return 0
case "":
usageShort()
return 0
default:
errf("Unknown command %q\n", cmd)
usageShort()
return 1
}
}
func usageShort() {
errf("Usage: %s [<options>] {help|init|up|ssh|save|down|poweroff|reset|restart|status|info|delete|download|version} [<args>]\n", os.Args[0])
}
func usageLong() {
// NOTE: the help message uses spaces, not tabs for indentation!
errf(`boot2docker management utility.
Usage: %s [<options>] <command> [<args>]
Commands:
init [<vm>] Create a new boot2docker VM.
up|start|boot [<vm>] Start VM from any states.
ssh Login to VM via SSH.
save|suspend [<vm>] Suspend VM and save state to disk.
down|stop|halt [<vm>] Gracefully shutdown the VM.
restart [<vm>] Gracefully reboot the VM.
poweroff [<vm>] Forcefully power off the VM (might corrupt disk image).
reset [<vm>] Forcefully power cycle the VM (might corrupt disk image).
delete [<vm>] Delete boot2docker VM and its disk image.
info [<vm>] Display detailed information of VM.
status [<vm>] Display current state of VM.
download Download boot2docker ISO image.
version Display version information.
Options:
`, os.Args[0])
flag.PrintDefaults()
}