Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fleetctl: set --driver=etcd if --endpoint is etcd-like
Browse files Browse the repository at this point in the history
  • Loading branch information
bcwaldon committed Apr 29, 2015
1 parent c52d517 commit 22be3e0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 22be3e0

Please sign in to comment.