Merge pull request #265 from vieux/no_discovery_flag

replace --discovery by argument
This commit is contained in:
Andrea Luzzardi
2015-01-21 14:28:40 -08:00
5 changed files with 48 additions and 14 deletions

View File

@@ -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",

25
help.go Normal file
View File

@@ -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:
swarm {{.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://<token>
{{printf "\t"}} * etcd://<ip1>,<ip2>/<path>
{{printf "\t"}} * file://path/to/file
{{printf "\t"}} * zk://<ip1>,<ip2>/<path>
{{printf "\t"}} * <ip1>,<ip2>{{end}}{{if .Flags}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{ end }}
`
}

View File

@@ -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)
}

11
main.go
View File

@@ -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,
},
}

View File

@@ -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)
}