From fb2731b5f228f5b086e7101884ff194901315cb1 Mon Sep 17 00:00:00 2001 From: Andrew Forgue Date: Fri, 4 Jul 2014 15:25:51 -0700 Subject: [PATCH] command: peers via ETCDCTL_PEERS env variable --- README.md | 9 +++++++++ command/handle.go | 8 +++++++- etcdctl.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 799351b..e88c524 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,15 @@ The following exit codes can be returned from etcdctl: 5 500 error from etcd ``` +## Peers + +If your etcd cluster isn't available on `http://127.0.0.1:4001` you can specify +a `--peers` flag or `ETCDCTL_PEERS` environment variable. + +``` +ETCDCTL_PEERS="http://10.0.28.1:4002" etcdctl set my-key to-a-value +``` + ## Project Details ### Versioning 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..04e6bab 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 comma-delimited list of machine addresses in the cluster (default: \"127.0.0.1:4001\")"}, } app.Commands = []cli.Command{ command.NewMakeCommand(),