forked from coreos/etcdctl
/
etcdctl.go
50 lines (38 loc) · 837 Bytes
/
etcdctl.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
package main
import (
"flag"
"fmt"
"github.com/coreos/go-etcd/etcd"
"os"
)
var (
cluster = flag.String("C", "0.0.0.0:4001", "a list of machine addresses in the cluster")
client = etcd.NewClient()
)
func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
os.Exit(1)
}
commandName := args[0]
command, ok := commands[commandName]
if !ok {
fmt.Println("wrong command provided")
os.Exit(MalformedEtcdctlArguments)
}
if len(args) > command.maxArgs || len(args) < command.minArgs {
fmt.Println("wrong arguments provided")
fmt.Println(command.usage)
os.Exit(MalformedEtcdctlArguments)
}
if !client.SyncCluster() {
fmt.Println("cannot sync with the given cluster")
os.Exit(FailedToConnectToHost)
}
err := command.f(args)
if err != nil {
fmt.Println(err)
os.Exit(ErrorFromEtcd)
}
}