Use actual binary name instead of hardcoding it

Signed-off-by: Radek Simko <radek.simko@gmail.com>
This commit is contained in:
Radek Simko 2015-01-23 07:36:07 +00:00
parent cb0baf349e
commit a1f4e44f09
4 changed files with 13 additions and 7 deletions

11
help.go
View File

@ -1,13 +1,18 @@
package main package main
import "github.com/codegangsta/cli" import (
"os"
"path"
"github.com/codegangsta/cli"
)
func init() { func init() {
// See https://github.com/codegangsta/cli/pull/171/files
cli.CommandHelpTemplate = `{{$DISCOVERY := or (eq .Name "manage") (eq .Name "join") (eq .Name "list")}}NAME: cli.CommandHelpTemplate = `{{$DISCOVERY := or (eq .Name "manage") (eq .Name "join") (eq .Name "list")}}NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
USAGE: USAGE:
swarm {{.Name}}{{if .Flags}} [options]{{end}} {{if $DISCOVERY}}<discovery>{{end}}{{if .Description}} ` + path.Base(os.Args[0]) + ` {{.Name}}{{if .Flags}} [options]{{end}} {{if $DISCOVERY}}<discovery>{{end}}{{if .Description}}
DESCRIPTION: DESCRIPTION:
{{.Description}}{{end}}{{if $DISCOVERY}} {{.Description}}{{end}}{{if $DISCOVERY}}
ARGUMENTS: ARGUMENTS:

View File

@ -17,7 +17,7 @@ func checkAddrFormat(addr string) bool {
func join(c *cli.Context) { func join(c *cli.Context) {
dflag := getDiscovery(c) dflag := getDiscovery(c)
if dflag == "" { if dflag == "" {
log.Fatal("discovery required to join a cluster. See 'swarm join --help'.") log.Fatalf("discovery required to join a cluster. See '%s join --help'.", c.App.Name)
} }
d, err := discovery.New(dflag, c.Int("heartbeat")) d, err := discovery.New(dflag, c.Int("heartbeat"))

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -18,7 +19,7 @@ import (
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "swarm" app.Name = path.Base(os.Args[0])
app.Usage = "a Docker-native clustering system" app.Usage = "a Docker-native clustering system"
app.Version = "0.1.0" app.Version = "0.1.0"
app.Author = "" app.Author = ""
@ -78,7 +79,7 @@ func main() {
Action: func(c *cli.Context) { Action: func(c *cli.Context) {
dflag := getDiscovery(c) dflag := getDiscovery(c)
if dflag == "" { if dflag == "" {
log.Fatal("discovery required to list a cluster. See 'swarm list --help'.") log.Fatalf("discovery required to list a cluster. See '%s list --help'.", c.App.Name)
} }
d, err := discovery.New(dflag, 0) d, err := discovery.New(dflag, 0)

View File

@ -83,7 +83,7 @@ func manage(c *cli.Context) {
dflag := getDiscovery(c) dflag := getDiscovery(c)
if dflag == "" { if dflag == "" {
log.Fatal("discovery required to manage a cluster. See 'swarm manage --help'.") log.Fatalf("discovery required to manage a cluster. See '%s manage --help'.", c.App.Name)
} }
s, err := strategy.New(c.String("strategy")) s, err := strategy.New(c.String("strategy"))