From 86a8dc0378c37ac5103f87bfa8255db680c4071b Mon Sep 17 00:00:00 2001 From: Andrew Forgue Date: Fri, 4 Jul 2014 15:25:51 -0700 Subject: [PATCH] Peer configuration via ETCDCTL_PEERS env variable --- command/handle.go | 8 +++++++- etcdctl.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/command/handle.go b/command/handle.go index 92c8857..b95b95c 100644 --- a/command/handle.go +++ b/command/handle.go @@ -44,7 +44,13 @@ func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) { peers := c.GlobalStringSlice("peers") // Append default peer address if not any if len(peers) == 0 { - peers = append(peers, "127.0.0.1:4001") + peers_from_environment := os.Getenv("ETCDCTL_PEERS") + + if peers_from_environment != "" { + peers = strings.Split(peers_from_environment, ",") + } else { + peers = append(peers, "127.0.0.1:4001") + } } // If no sync, create http path for each peer address if !sync { diff --git a/etcdctl.go b/etcdctl.go index 48bb65a..629fdd2 100644 --- a/etcdctl.go +++ b/etcdctl.go @@ -16,7 +16,7 @@ func main() { cli.BoolFlag{"debug", "output cURL commands which can be used to reproduce the request"}, cli.BoolFlag{"no-sync", "don't synchronize cluster information before sending request"}, cli.StringFlag{"output, o", "simple", "output response in the given format (`simple` or `json`)"}, - cli.StringSliceFlag{"peers, C", &cli.StringSlice{}, "a comma-delimited list of machine addresses in the cluster (default: {\"127.0.0.1:4001\"})"}, + cli.StringSliceFlag{"peers, C", &cli.StringSlice{}, "a list of peers in the cluster, specify multiple times for multiple peers. (default: 127.0.0.1:4001 or ETCDCTL_PEERS environment variable)"}, } app.Commands = []cli.Command{ command.NewMakeCommand(),