forked from hyperhq/hyperd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyper.go
45 lines (40 loc) · 858 Bytes
/
hyper.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
package main
import (
"flag"
"fmt"
"github.com/hyperhq/hyper/client"
"os"
)
func main() {
var (
proto = "unix"
addr = "/var/run/hyper.sock"
)
cli := client.NewHyperClient(proto, addr, nil)
// set the flag to output
flHelp := flag.Bool("help", false, "Help Message")
flVersion := flag.Bool("version", false, "Version Message")
flag.Usage = func() { cli.Cmd("help") }
flag.Parse()
if flag.NArg() == 0 {
cli.Cmd("help")
return
}
if *flHelp == true {
cli.Cmd("help")
}
if *flVersion == true {
cli.Cmd("version")
}
if err := cli.Cmd(flag.Args()...); err != nil {
if sterr, ok := err.(client.StatusError); ok {
if sterr.Status != "" {
fmt.Printf("%s ERROR: %s\n", os.Args[0], err.Error())
os.Exit(-1)
}
os.Exit(sterr.StatusCode)
}
fmt.Printf("%s ERROR: %s\n", os.Args[0], err.Error())
os.Exit(-1)
}
}