From 22be3e027dc11a025e6f08455ea627fff4c21133 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 28 Apr 2015 17:57:48 -0700 Subject: [PATCH] fleetctl: set --driver=etcd if --endpoint is etcd-like --- fleetctl/fleetctl.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fleetctl/fleetctl.go b/fleetctl/fleetctl.go index ea0cee87b..8d2bf298c 100644 --- a/fleetctl/fleetctl.go +++ b/fleetctl/fleetctl.go @@ -262,6 +262,20 @@ func main() { os.Exit(2) } + visited := make(map[string]bool, 0) + globalFlagset.Visit(func(f *flag.Flag) { visited[f.Name] = true }) + + // if --driver is not set, but --endpoint looks like an etcd + // server, set the driver to etcd + if visited["endpoint"] && !visited["driver"] { + if u, err := url.Parse(strings.Split(globalFlags.Endpoint, ",")[0]); err == nil { + if _, port, err := net.SplitHostPort(u.Host); err == nil && (port == "4001" || port == "2379") { + log.Debugf("Defaulting to --driver=%s as --endpoint appears to be etcd", clientDriverEtcd) + globalFlags.ClientDriver = clientDriverEtcd + } + } + } + if cmd.Name != "help" && cmd.Name != "version" { var err error cAPI, err = getClient()