diff options
author | Maximilian Meister <mmeister@suse.de> | 2017-08-11 19:29:05 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-08-11 19:29:05 +0800 |
commit | 2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e (patch) | |
tree | fe732b8be4c6ec4fb11ed78078b54144fcb4affc /vendor/gopkg.in/urfave/cli.v1/command.go | |
parent | 73c5aba21fcca1bf1f78e94d88920fde6762be9e (diff) | |
download | go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar.gz go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar.bz2 go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar.lz go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar.xz go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.tar.zst go-tangerine-2b422b1a47e9b2a0f3d7ecf7063eef2e59cc082e.zip |
cmd/geth, cmd/swarm: sort commands and flags by name (#3462)
Diffstat (limited to 'vendor/gopkg.in/urfave/cli.v1/command.go')
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/command.go | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/vendor/gopkg.in/urfave/cli.v1/command.go b/vendor/gopkg.in/urfave/cli.v1/command.go index 2628fbf48..23de2944b 100644 --- a/vendor/gopkg.in/urfave/cli.v1/command.go +++ b/vendor/gopkg.in/urfave/cli.v1/command.go @@ -59,6 +59,25 @@ type Command struct { // Full name of command for help, defaults to full command name, including parent commands. HelpName string commandNamePath []string + + // CustomHelpTemplate the text template for the command help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomHelpTemplate string +} + +type CommandsByName []Command + +func (c CommandsByName) Len() int { + return len(c) +} + +func (c CommandsByName) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandsByName) Swap(i, j int) { + c[i], c[j] = c[j], c[i] } // FullName returns the full name of the command. @@ -140,19 +159,20 @@ func (c Command) Run(ctx *Context) (err error) { } context := NewContext(ctx.App, set, ctx) + context.Command = c if checkCommandCompletions(context, c.Name) { return nil } if err != nil { if c.OnUsageError != nil { - err := c.OnUsageError(ctx, err, false) + err := c.OnUsageError(context, err, false) HandleExitCoder(err) return err } - fmt.Fprintln(ctx.App.Writer, "Incorrect Usage:", err.Error()) - fmt.Fprintln(ctx.App.Writer) - ShowCommandHelp(ctx, c.Name) + fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) + fmt.Fprintln(context.App.Writer) + ShowCommandHelp(context, c.Name) return err } @@ -177,9 +197,7 @@ func (c Command) Run(ctx *Context) (err error) { if c.Before != nil { err = c.Before(context) if err != nil { - fmt.Fprintln(ctx.App.Writer, err) - fmt.Fprintln(ctx.App.Writer) - ShowCommandHelp(ctx, c.Name) + ShowCommandHelp(context, c.Name) HandleExitCoder(err) return err } @@ -189,7 +207,6 @@ func (c Command) Run(ctx *Context) (err error) { c.Action = helpSubcommand.Action } - context.Command = c err = HandleAction(c.Action, context) if err != nil { @@ -230,14 +247,13 @@ func (c Command) startApp(ctx *Context) error { app.HelpName = app.Name } - if c.Description != "" { - app.Usage = c.Description - } else { - app.Usage = c.Usage - } + app.Usage = c.Usage + app.Description = c.Description + app.ArgsUsage = c.ArgsUsage // set CommandNotFound app.CommandNotFound = ctx.App.CommandNotFound + app.CustomAppHelpTemplate = c.CustomHelpTemplate // set the flags and commands app.Commands = c.Subcommands @@ -250,6 +266,7 @@ func (c Command) startApp(ctx *Context) error { app.Author = ctx.App.Author app.Email = ctx.App.Email app.Writer = ctx.App.Writer + app.ErrWriter = ctx.App.ErrWriter app.categories = CommandCategories{} for _, command := range c.Subcommands { @@ -272,6 +289,7 @@ func (c Command) startApp(ctx *Context) error { } else { app.Action = helpSubcommand.Action } + app.OnUsageError = c.OnUsageError for index, cc := range app.Commands { app.Commands[index].commandNamePath = []string{c.Name, cc.Name} |