diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-10-30 01:53:24 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-10-30 17:33:12 +0800 |
commit | 3c6e285d3bfa03935f4f346a2cb32236143e2fca (patch) | |
tree | b433f27f43ebfab6efb06cfbb0d4d8db039fbefc /Godeps/_workspace/src/github.com/codegangsta/cli/command.go | |
parent | fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3 (diff) | |
download | go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar.gz go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar.bz2 go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar.lz go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar.xz go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.tar.zst go-tangerine-3c6e285d3bfa03935f4f346a2cb32236143e2fca.zip |
cmd/geth, cmd/utils, eth: group CLI flags by purpose
Diffstat (limited to 'Godeps/_workspace/src/github.com/codegangsta/cli/command.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/codegangsta/cli/command.go | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/Godeps/_workspace/src/github.com/codegangsta/cli/command.go b/Godeps/_workspace/src/github.com/codegangsta/cli/command.go index b61691c86..fac754deb 100644 --- a/Godeps/_workspace/src/github.com/codegangsta/cli/command.go +++ b/Godeps/_workspace/src/github.com/codegangsta/cli/command.go @@ -18,6 +18,8 @@ type Command struct { Usage string // A longer explanation of how the command works Description string + // A short description of the arguments of this command + ArgsUsage string // The function to call when checking for bash command completions BashComplete func(context *Context) // An action to execute before any sub-subcommands are run, but after the context is ready @@ -36,11 +38,23 @@ type Command struct { SkipFlagParsing bool // Boolean to hide built-in help command HideHelp bool + + // Full name of command for help, defaults to full command name, including parent commands. + HelpName string + commandNamePath []string +} + +// Returns the full name of the command. +// For subcommands this ensures that parent commands are part of the command path +func (c Command) FullName() string { + if c.commandNamePath == nil { + return c.Name + } + return strings.Join(c.commandNamePath, " ") } // Invokes the command given the context, parses ctx.Args() to generate command-specific flags func (c Command) Run(ctx *Context) error { - if len(c.Subcommands) > 0 || c.Before != nil || c.After != nil { return c.startApp(ctx) } @@ -91,9 +105,9 @@ func (c Command) Run(ctx *Context) error { } if err != nil { - fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n") - ShowCommandHelp(ctx, c.Name) + fmt.Fprintln(ctx.App.Writer, "Incorrect Usage.") fmt.Fprintln(ctx.App.Writer) + ShowCommandHelp(ctx, c.Name) return err } @@ -102,10 +116,9 @@ func (c Command) Run(ctx *Context) error { fmt.Fprintln(ctx.App.Writer, nerr) fmt.Fprintln(ctx.App.Writer) ShowCommandHelp(ctx, c.Name) - fmt.Fprintln(ctx.App.Writer) return nerr } - context := NewContext(ctx.App, set, ctx.globalSet) + context := NewContext(ctx.App, set, ctx) if checkCommandCompletions(context, c.Name) { return nil @@ -144,6 +157,12 @@ func (c Command) startApp(ctx *Context) error { // set the name and usage app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) + if c.HelpName == "" { + app.HelpName = c.HelpName + } else { + app.HelpName = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) + } + if c.Description != "" { app.Usage = c.Description } else { @@ -158,6 +177,13 @@ func (c Command) startApp(ctx *Context) error { app.Flags = c.Flags app.HideHelp = c.HideHelp + app.Version = ctx.App.Version + app.HideVersion = ctx.App.HideVersion + app.Compiled = ctx.App.Compiled + app.Author = ctx.App.Author + app.Email = ctx.App.Email + app.Writer = ctx.App.Writer + // bash completion app.EnableBashCompletion = ctx.App.EnableBashCompletion if c.BashComplete != nil { @@ -173,5 +199,12 @@ func (c Command) startApp(ctx *Context) error { app.Action = helpSubcommand.Action } + var newCmds []Command + for _, cc := range app.Commands { + cc.commandNamePath = []string{c.Name, cc.Name} + newCmds = append(newCmds, cc) + } + app.Commands = newCmds + return app.RunAsSubcommand(ctx) } |