summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/urfave/cli/command.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-05-03 14:49:14 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-05-03 08:49:14 -0400
commit2933ae4e88bb954af76c4e1e67c7ab1e4892e4a4 (patch)
tree15cd01e1175514ee8ff8a9179dc102505d00f1f5 /vendor/github.com/urfave/cli/command.go
parentdbb0c9658c637bb987ec7d09a43be5ace5ac6708 (diff)
downloadgitea-2933ae4e88bb954af76c4e1e67c7ab1e4892e4a4.tar.gz
gitea-2933ae4e88bb954af76c4e1e67c7ab1e4892e4a4.zip
Update https://github.com/urfave/cli to version 1.2.0 (#6838)
From un-tagged pervious version : https://github.com/urfave/cli/compare/d86a009f5e13...master
Diffstat (limited to 'vendor/github.com/urfave/cli/command.go')
-rw-r--r--vendor/github.com/urfave/cli/command.go72
1 files changed, 46 insertions, 26 deletions
diff --git a/vendor/github.com/urfave/cli/command.go b/vendor/github.com/urfave/cli/command.go
index d9552499de..23de2944be 100644
--- a/vendor/github.com/urfave/cli/command.go
+++ b/vendor/github.com/urfave/cli/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.
@@ -87,11 +106,10 @@ func (c Command) Run(ctx *Context) (err error) {
)
}
- if ctx.App.EnableBashCompletion {
- c.Flags = append(c.Flags, BashCompletionFlag)
+ set, err := flagSet(c.Name, c.Flags)
+ if err != nil {
+ return err
}
-
- set := flagSet(c.Name, c.Flags)
set.SetOutput(ioutil.Discard)
if c.SkipFlagParsing {
@@ -132,18 +150,6 @@ func (c Command) Run(ctx *Context) (err error) {
err = set.Parse(ctx.Args().Tail())
}
- if err != nil {
- if c.OnUsageError != nil {
- err := c.OnUsageError(ctx, err, false)
- HandleExitCoder(err)
- return err
- }
- fmt.Fprintln(ctx.App.Writer, "Incorrect Usage:", err.Error())
- fmt.Fprintln(ctx.App.Writer)
- ShowCommandHelp(ctx, c.Name)
- return err
- }
-
nerr := normalizeFlags(c.Flags, set)
if nerr != nil {
fmt.Fprintln(ctx.App.Writer, nerr)
@@ -153,11 +159,23 @@ 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(context, err, false)
+ HandleExitCoder(err)
+ return err
+ }
+ fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
+ fmt.Fprintln(context.App.Writer)
+ ShowCommandHelp(context, c.Name)
+ return err
+ }
+
if checkCommandHelp(context, c.Name) {
return nil
}
@@ -179,15 +197,16 @@ 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
}
}
- context.Command = c
+ if c.Action == nil {
+ c.Action = helpSubcommand.Action
+ }
+
err = HandleAction(c.Action, context)
if err != nil {
@@ -228,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
@@ -248,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 {
@@ -270,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}