From 3fe99c7067112af0c15c4ac482af3219a7e874c5 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 21 Jan 2015 19:59:27 +0000 Subject: [PATCH 1/2] replace --discovery by argument Signed-off-by: Victor Vieux --- flags.go | 11 ++++++++++- help.go | 25 +++++++++++++++++++++++++ join.go | 8 ++++---- main.go | 11 +++++------ manage.go | 7 ++++--- 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 help.go diff --git a/flags.go b/flags.go index d164a0a683..f3dbd18108 100644 --- a/flags.go +++ b/flags.go @@ -1,10 +1,12 @@ package main import ( - "github.com/codegangsta/cli" + "os" "os/user" "path" + "github.com/codegangsta/cli" + log "github.com/Sirupsen/logrus" ) @@ -16,6 +18,13 @@ func homepath(p string) string { return path.Join(usr.HomeDir, p) } +func getDiscovery(c *cli.Context) string { + if len(c.Args()) == 1 { + return c.Args()[0] + } + return os.Getenv("SWARM_DISCOVERY") +} + var ( flStore = cli.StringFlag{ Name: "rootdir", diff --git a/help.go b/help.go new file mode 100644 index 0000000000..8ac640b1fe --- /dev/null +++ b/help.go @@ -0,0 +1,25 @@ +package main + +import "github.com/codegangsta/cli" + +func init() { + + cli.CommandHelpTemplate = `{{$DISCOVERY := or (eq .Name "manage") (eq .Name "join") (eq .Name "list")}}NAME: + {{.Name}} - {{.Usage}} +USAGE: + command {{.Name}}{{if .Flags}} [command options]{{end}} {{if $DISCOVERY}}[discovery]{{end}}{{if .Description}} +DESCRIPTION: + {{.Description}}{{end}}{{if $DISCOVERY}} +ARGUMENTS: + discovery{{printf "\t"}}discovery service to use [$SWARM_DISCOVERY] + {{printf "\t"}} * token:// + {{printf "\t"}} * etcd://,/ + {{printf "\t"}} * file://path/to/file + {{printf "\t"}} * zk://,/ + {{printf "\t"}} * ,{{end}}{{if .Flags}} +OPTIONS: + {{range .Flags}}{{.}} + {{end}}{{ end }} +` + +} diff --git a/join.go b/join.go index 0a20ff3382..9446d79722 100644 --- a/join.go +++ b/join.go @@ -15,12 +15,12 @@ func checkAddrFormat(addr string) bool { } func join(c *cli.Context) { - - if c.String("discovery") == "" { - log.Fatal("--discovery required to join a cluster") + dflag := getDiscovery(c) + if dflag == "" { + log.Fatal("discovery required to join a cluster. See 'swarm join --help'.") } - d, err := discovery.New(c.String("discovery"), c.Int("heartbeat")) + d, err := discovery.New(dflag, c.Int("heartbeat")) if err != nil { log.Fatal(err) } diff --git a/main.go b/main.go index a555b1e0da..fba11ae80d 100644 --- a/main.go +++ b/main.go @@ -60,13 +60,13 @@ func main() { Name: "list", ShortName: "l", Usage: "list nodes in a cluster", - Flags: []cli.Flag{flDiscovery}, Action: func(c *cli.Context) { - if c.String("discovery") == "" { - log.Fatal("--discovery required to list a cluster") + dflag := getDiscovery(c) + if dflag == "" { + log.Fatal("discovery required to list a cluster. See 'swarm list --help'.") } - d, err := discovery.New(c.String("discovery"), 0) + d, err := discovery.New(dflag, 0) if err != nil { log.Fatal(err) } @@ -85,7 +85,6 @@ func main() { ShortName: "m", Usage: "manage a docker cluster", Flags: []cli.Flag{ - flDiscovery, flStore, flStrategy, flFilter, flHosts, flHeartBeat, flOverCommit, @@ -97,7 +96,7 @@ func main() { Name: "join", ShortName: "j", Usage: "join a docker cluster", - Flags: []cli.Flag{flDiscovery, flAddr, flHeartBeat}, + Flags: []cli.Flag{flAddr, flHeartBeat}, Action: join, }, } diff --git a/manage.go b/manage.go index 2c6fd39f05..b478308fc2 100644 --- a/manage.go +++ b/manage.go @@ -81,8 +81,9 @@ func manage(c *cli.Context) { cluster := cluster.NewCluster(store, tlsConfig, c.Float64("overcommit")) cluster.Events(&logHandler{}) - if c.String("discovery") == "" { - log.Fatal("--discovery required to manage a cluster") + dflag := getDiscovery(c) + if dflag == "" { + log.Fatal("discovery required to manage a cluster. See 'swarm manage --help'.") } s, err := strategy.New(c.String("strategy")) @@ -102,7 +103,7 @@ func manage(c *cli.Context) { // get the list of nodes from the discovery service go func() { - d, err := discovery.New(c.String("discovery"), c.Int("heartbeat")) + d, err := discovery.New(dflag, c.Int("heartbeat")) if err != nil { log.Fatal(err) } From 09f38991acefae12ae755e21eaf3b068eb18a78a Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 21 Jan 2015 20:11:17 +0000 Subject: [PATCH 2/2] replace command by swarm in usage Signed-off-by: Victor Vieux --- help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help.go b/help.go index 8ac640b1fe..cf06c4ab2c 100644 --- a/help.go +++ b/help.go @@ -7,7 +7,7 @@ func init() { cli.CommandHelpTemplate = `{{$DISCOVERY := or (eq .Name "manage") (eq .Name "join") (eq .Name "list")}}NAME: {{.Name}} - {{.Usage}} USAGE: - command {{.Name}}{{if .Flags}} [command options]{{end}} {{if $DISCOVERY}}[discovery]{{end}}{{if .Description}} + swarm {{.Name}}{{if .Flags}} [command options]{{end}} {{if $DISCOVERY}}[discovery]{{end}}{{if .Description}} DESCRIPTION: {{.Description}}{{end}}{{if $DISCOVERY}} ARGUMENTS: