diff --git a/etcdctl.go b/etcdctl.go index 8cc51d3..60f87c1 100644 --- a/etcdctl.go +++ b/etcdctl.go @@ -8,13 +8,16 @@ import ( ) var ( - cluster = flag.String("C", "0.0.0.0:4001", "a list of machine addresses in the cluster") - client = etcd.NewClient() + client *etcd.Client ) func main() { + cluster := ClusterValue{"http://localhost:4001"} + 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") flag.Parse() + client = etcd.NewClient(cluster.GetMachines()) + args := flag.Args() if len(args) == 0 { diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..3c92ad1 --- /dev/null +++ b/flags.go @@ -0,0 +1,27 @@ +package main + +import ( + "strings" +) + +type ClusterValue struct { + machines string +} + +func (c *ClusterValue) String() string { + return c.machines +} + +func (c *ClusterValue) Set(value string) error { + if len(value) == 0 { + return nil + } + + c.machines = value + + return nil +} + +func (c *ClusterValue) GetMachines() []string { + return strings.Split(c.machines, ",") +}