github.com/slantview/etcdctl@v0.1.3-0.20131011185546-5aaeca137f94/etcdctl.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "github.com/coreos/go-etcd/etcd" 7 "os" 8 ) 9 10 var ( 11 client *etcd.Client 12 13 printVersion bool 14 ) 15 16 func main() { 17 flag.BoolVar(&printVersion, "version", false, "print the version and exit") 18 19 cluster := ClusterValue{"http://localhost:4001"} 20 flag.Var(&cluster, "C", "a comma seperated list of machine addresses in the cluster e.g. 127.0.0.1:4001,127.0.0.1:4002") 21 flag.Parse() 22 23 if printVersion { 24 fmt.Println(releaseVersion) 25 os.Exit(0) 26 } 27 28 client = etcd.NewClient(cluster.GetMachines()) 29 30 args := flag.Args() 31 32 if len(args) == 0 { 33 os.Exit(1) 34 } 35 36 commandName := args[0] 37 38 command, ok := commands[commandName] 39 40 if !ok { 41 fmt.Println("wrong command provided") 42 os.Exit(MalformedEtcdctlArguments) 43 } 44 45 if len(args) > command.maxArgs || len(args) < command.minArgs { 46 fmt.Println("wrong arguments provided") 47 fmt.Println(command.usage) 48 os.Exit(MalformedEtcdctlArguments) 49 } 50 51 if !client.SyncCluster() { 52 fmt.Println("cannot sync with the given cluster") 53 os.Exit(FailedToConnectToHost) 54 } 55 56 err := command.f(args) 57 58 if err != nil { 59 fmt.Println(err) 60 os.Exit(ErrorFromEtcd) 61 } 62 }