Merge pull request #1688 from crosbymichael/cli
Update cli to 7bc6a0acffa589f415f88aca16cc1de5ffd6
This commit is contained in:
commit
1f704e9862
@ -23,7 +23,7 @@ github.com/stretchr/testify v1.1.4
|
|||||||
github.com/davecgh/go-spew v1.1.0
|
github.com/davecgh/go-spew v1.1.0
|
||||||
github.com/pmezard/go-difflib v1.0.0
|
github.com/pmezard/go-difflib v1.0.0
|
||||||
github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6
|
github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6
|
||||||
github.com/urfave/cli 8ba6f23b6e36d03666a14bd9421f5e3efcb59aca
|
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
|
||||||
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
|
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
|
||||||
google.golang.org/grpc v1.3.0
|
google.golang.org/grpc v1.3.0
|
||||||
github.com/pkg/errors v0.8.0
|
github.com/pkg/errors v0.8.0
|
||||||
|
14
vendor/github.com/urfave/cli/README.md
generated
vendored
14
vendor/github.com/urfave/cli/README.md
generated
vendored
@ -33,6 +33,7 @@ applications in an expressive way.
|
|||||||
+ [Ordering](#ordering)
|
+ [Ordering](#ordering)
|
||||||
+ [Values from the Environment](#values-from-the-environment)
|
+ [Values from the Environment](#values-from-the-environment)
|
||||||
+ [Values from alternate input sources (YAML, TOML, and others)](#values-from-alternate-input-sources-yaml-toml-and-others)
|
+ [Values from alternate input sources (YAML, TOML, and others)](#values-from-alternate-input-sources-yaml-toml-and-others)
|
||||||
|
+ [Precedence](#precedence)
|
||||||
* [Subcommands](#subcommands)
|
* [Subcommands](#subcommands)
|
||||||
* [Subcommands categories](#subcommands-categories)
|
* [Subcommands categories](#subcommands-categories)
|
||||||
* [Exit code](#exit-code)
|
* [Exit code](#exit-code)
|
||||||
@ -656,6 +657,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Precedence
|
||||||
|
|
||||||
|
The precedence for flag value sources is as follows (highest to lowest):
|
||||||
|
|
||||||
|
0. Command line flag value from user
|
||||||
|
0. Environment variable (if specified)
|
||||||
|
0. Configuration file (if specified)
|
||||||
|
0. Default defined on the flag
|
||||||
|
|
||||||
### Subcommands
|
### Subcommands
|
||||||
|
|
||||||
Subcommands can be defined for a more git-like command line app.
|
Subcommands can be defined for a more git-like command line app.
|
||||||
@ -751,11 +761,11 @@ func main() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "add",
|
Name: "add",
|
||||||
Category: "template",
|
Category: "Template actions",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
Category: "template",
|
Category: "Template actions",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
vendor/github.com/urfave/cli/app.go
generated
vendored
35
vendor/github.com/urfave/cli/app.go
generated
vendored
@ -83,8 +83,17 @@ type App struct {
|
|||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
// ErrWriter writes error output
|
// ErrWriter writes error output
|
||||||
ErrWriter io.Writer
|
ErrWriter io.Writer
|
||||||
|
// Execute this function to handle ExitErrors. If not provided, HandleExitCoder is provided to
|
||||||
|
// function as a default, so this is optional.
|
||||||
|
ExitErrHandler ExitErrHandlerFunc
|
||||||
// Other custom info
|
// Other custom info
|
||||||
Metadata map[string]interface{}
|
Metadata map[string]interface{}
|
||||||
|
// Carries a function which returns app specific info.
|
||||||
|
ExtraInfo func() map[string]string
|
||||||
|
// CustomAppHelpTemplate the text template for app help topic.
|
||||||
|
// cli.go uses text/template to render templates. You can
|
||||||
|
// render custom help text by setting this variable.
|
||||||
|
CustomAppHelpTemplate string
|
||||||
|
|
||||||
didSetup bool
|
didSetup bool
|
||||||
}
|
}
|
||||||
@ -201,7 +210,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if a.OnUsageError != nil {
|
if a.OnUsageError != nil {
|
||||||
err := a.OnUsageError(context, err, false)
|
err := a.OnUsageError(context, err, false)
|
||||||
HandleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
@ -236,7 +245,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
||||||
ShowAppHelp(context)
|
ShowAppHelp(context)
|
||||||
HandleExitCoder(beforeErr)
|
a.handleExitCoder(context, beforeErr)
|
||||||
err = beforeErr
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -258,7 +267,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
// Run default Action
|
// Run default Action
|
||||||
err = HandleAction(a.Action, context)
|
err = HandleAction(a.Action, context)
|
||||||
|
|
||||||
HandleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +334,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if a.OnUsageError != nil {
|
if a.OnUsageError != nil {
|
||||||
err = a.OnUsageError(context, err, true)
|
err = a.OnUsageError(context, err, true)
|
||||||
HandleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
@ -347,7 +356,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
afterErr := a.After(context)
|
afterErr := a.After(context)
|
||||||
if afterErr != nil {
|
if afterErr != nil {
|
||||||
HandleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = NewMultiError(err, afterErr)
|
err = NewMultiError(err, afterErr)
|
||||||
} else {
|
} else {
|
||||||
@ -360,7 +369,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
beforeErr := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
HandleExitCoder(beforeErr)
|
a.handleExitCoder(context, beforeErr)
|
||||||
err = beforeErr
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -378,7 +387,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
// Run default Action
|
// Run default Action
|
||||||
err = HandleAction(a.Action, context)
|
err = HandleAction(a.Action, context)
|
||||||
|
|
||||||
HandleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,6 +468,14 @@ func (a *App) appendFlag(flag Flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) handleExitCoder(context *Context, err error) {
|
||||||
|
if a.ExitErrHandler != nil {
|
||||||
|
a.ExitErrHandler(context, err)
|
||||||
|
} else {
|
||||||
|
HandleExitCoder(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Author represents someone who has contributed to a cli project.
|
// Author represents someone who has contributed to a cli project.
|
||||||
type Author struct {
|
type Author struct {
|
||||||
Name string // The Authors name
|
Name string // The Authors name
|
||||||
@ -486,7 +503,7 @@ func HandleAction(action interface{}, context *Context) (err error) {
|
|||||||
} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
|
} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
|
||||||
a(context)
|
a(context)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return errInvalidActionType
|
return errInvalidActionType
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
1
vendor/github.com/urfave/cli/cli.go
generated
vendored
1
vendor/github.com/urfave/cli/cli.go
generated
vendored
@ -12,6 +12,7 @@
|
|||||||
// app.Usage = "say a greeting"
|
// app.Usage = "say a greeting"
|
||||||
// app.Action = func(c *cli.Context) error {
|
// app.Action = func(c *cli.Context) error {
|
||||||
// println("Greetings")
|
// println("Greetings")
|
||||||
|
// return nil
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// app.Run(os.Args)
|
// app.Run(os.Args)
|
||||||
|
29
vendor/github.com/urfave/cli/command.go
generated
vendored
29
vendor/github.com/urfave/cli/command.go
generated
vendored
@ -59,6 +59,11 @@ type Command struct {
|
|||||||
// Full name of command for help, defaults to full command name, including parent commands.
|
// Full name of command for help, defaults to full command name, including parent commands.
|
||||||
HelpName string
|
HelpName string
|
||||||
commandNamePath []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
|
type CommandsByName []Command
|
||||||
@ -154,19 +159,20 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context := NewContext(ctx.App, set, ctx)
|
context := NewContext(ctx.App, set, ctx)
|
||||||
|
context.Command = c
|
||||||
if checkCommandCompletions(context, c.Name) {
|
if checkCommandCompletions(context, c.Name) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.OnUsageError != nil {
|
if c.OnUsageError != nil {
|
||||||
err := c.OnUsageError(ctx, err, false)
|
err := c.OnUsageError(context, err, false)
|
||||||
HandleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(ctx.App.Writer, "Incorrect Usage:", err.Error())
|
fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
fmt.Fprintln(context.App.Writer)
|
||||||
ShowCommandHelp(ctx, c.Name)
|
ShowCommandHelp(context, c.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +184,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
afterErr := c.After(context)
|
afterErr := c.After(context)
|
||||||
if afterErr != nil {
|
if afterErr != nil {
|
||||||
HandleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = NewMultiError(err, afterErr)
|
err = NewMultiError(err, afterErr)
|
||||||
} else {
|
} else {
|
||||||
@ -191,10 +197,8 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
if c.Before != nil {
|
if c.Before != nil {
|
||||||
err = c.Before(context)
|
err = c.Before(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(ctx.App.Writer, err)
|
ShowCommandHelp(context, c.Name)
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
context.App.handleExitCoder(context, err)
|
||||||
ShowCommandHelp(ctx, c.Name)
|
|
||||||
HandleExitCoder(err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,11 +207,10 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
c.Action = helpSubcommand.Action
|
c.Action = helpSubcommand.Action
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Command = c
|
|
||||||
err = HandleAction(c.Action, context)
|
err = HandleAction(c.Action, context)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
HandleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -250,6 +253,7 @@ func (c Command) startApp(ctx *Context) error {
|
|||||||
|
|
||||||
// set CommandNotFound
|
// set CommandNotFound
|
||||||
app.CommandNotFound = ctx.App.CommandNotFound
|
app.CommandNotFound = ctx.App.CommandNotFound
|
||||||
|
app.CustomAppHelpTemplate = c.CustomHelpTemplate
|
||||||
|
|
||||||
// set the flags and commands
|
// set the flags and commands
|
||||||
app.Commands = c.Subcommands
|
app.Commands = c.Subcommands
|
||||||
@ -285,6 +289,7 @@ func (c Command) startApp(ctx *Context) error {
|
|||||||
} else {
|
} else {
|
||||||
app.Action = helpSubcommand.Action
|
app.Action = helpSubcommand.Action
|
||||||
}
|
}
|
||||||
|
app.OnUsageError = c.OnUsageError
|
||||||
|
|
||||||
for index, cc := range app.Commands {
|
for index, cc := range app.Commands {
|
||||||
app.Commands[index].commandNamePath = []string{c.Name, cc.Name}
|
app.Commands[index].commandNamePath = []string{c.Name, cc.Name}
|
||||||
|
4
vendor/github.com/urfave/cli/context.go
generated
vendored
4
vendor/github.com/urfave/cli/context.go
generated
vendored
@ -39,11 +39,13 @@ func (c *Context) NumFlags() int {
|
|||||||
|
|
||||||
// Set sets a context flag to a value.
|
// Set sets a context flag to a value.
|
||||||
func (c *Context) Set(name, value string) error {
|
func (c *Context) Set(name, value string) error {
|
||||||
|
c.setFlags = nil
|
||||||
return c.flagSet.Set(name, value)
|
return c.flagSet.Set(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalSet sets a context flag to a value on the global flagset
|
// GlobalSet sets a context flag to a value on the global flagset
|
||||||
func (c *Context) GlobalSet(name, value string) error {
|
func (c *Context) GlobalSet(name, value string) error {
|
||||||
|
globalContext(c).setFlags = nil
|
||||||
return globalContext(c).flagSet.Set(name, value)
|
return globalContext(c).flagSet.Set(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ func (c *Context) IsSet(name string) bool {
|
|||||||
// change in version 2 to add `IsSet` to the Flag interface to push the
|
// change in version 2 to add `IsSet` to the Flag interface to push the
|
||||||
// responsibility closer to where the information required to determine
|
// responsibility closer to where the information required to determine
|
||||||
// whether a flag is set by non-standard means such as environment
|
// whether a flag is set by non-standard means such as environment
|
||||||
// variables is avaliable.
|
// variables is available.
|
||||||
//
|
//
|
||||||
// See https://github.com/urfave/cli/issues/294 for additional discussion
|
// See https://github.com/urfave/cli/issues/294 for additional discussion
|
||||||
flags := c.Command.Flags
|
flags := c.Command.Flags
|
||||||
|
32
vendor/github.com/urfave/cli/flag.go
generated
vendored
32
vendor/github.com/urfave/cli/flag.go
generated
vendored
@ -14,13 +14,13 @@ import (
|
|||||||
const defaultPlaceholder = "value"
|
const defaultPlaceholder = "value"
|
||||||
|
|
||||||
// BashCompletionFlag enables bash-completion for all commands and subcommands
|
// BashCompletionFlag enables bash-completion for all commands and subcommands
|
||||||
var BashCompletionFlag = BoolFlag{
|
var BashCompletionFlag Flag = BoolFlag{
|
||||||
Name: "generate-bash-completion",
|
Name: "generate-bash-completion",
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionFlag prints the version for the application
|
// VersionFlag prints the version for the application
|
||||||
var VersionFlag = BoolFlag{
|
var VersionFlag Flag = BoolFlag{
|
||||||
Name: "version, v",
|
Name: "version, v",
|
||||||
Usage: "print the version",
|
Usage: "print the version",
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ var VersionFlag = BoolFlag{
|
|||||||
// HelpFlag prints the help for all commands and subcommands
|
// HelpFlag prints the help for all commands and subcommands
|
||||||
// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
|
// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
|
||||||
// unless HideHelp is set to true)
|
// unless HideHelp is set to true)
|
||||||
var HelpFlag = BoolFlag{
|
var HelpFlag Flag = BoolFlag{
|
||||||
Name: "help, h",
|
Name: "help, h",
|
||||||
Usage: "show help",
|
Usage: "show help",
|
||||||
}
|
}
|
||||||
@ -37,6 +37,14 @@ var HelpFlag = BoolFlag{
|
|||||||
// to display a flag.
|
// to display a flag.
|
||||||
var FlagStringer FlagStringFunc = stringifyFlag
|
var FlagStringer FlagStringFunc = stringifyFlag
|
||||||
|
|
||||||
|
// FlagNamePrefixer converts a full flag name and its placeholder into the help
|
||||||
|
// message flag prefix. This is used by the default FlagStringer.
|
||||||
|
var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames
|
||||||
|
|
||||||
|
// FlagEnvHinter annotates flag help message with the environment variable
|
||||||
|
// details. This is used by the default FlagStringer.
|
||||||
|
var FlagEnvHinter FlagEnvHintFunc = withEnvHint
|
||||||
|
|
||||||
// FlagsByName is a slice of Flag.
|
// FlagsByName is a slice of Flag.
|
||||||
type FlagsByName []Flag
|
type FlagsByName []Flag
|
||||||
|
|
||||||
@ -630,7 +638,8 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
func visibleFlags(fl []Flag) []Flag {
|
func visibleFlags(fl []Flag) []Flag {
|
||||||
visible := []Flag{}
|
visible := []Flag{}
|
||||||
for _, flag := range fl {
|
for _, flag := range fl {
|
||||||
if !flagValue(flag).FieldByName("Hidden").Bool() {
|
field := flagValue(flag).FieldByName("Hidden")
|
||||||
|
if !field.IsValid() || !field.Bool() {
|
||||||
visible = append(visible, flag)
|
visible = append(visible, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -709,13 +718,13 @@ func stringifyFlag(f Flag) string {
|
|||||||
|
|
||||||
switch f.(type) {
|
switch f.(type) {
|
||||||
case IntSliceFlag:
|
case IntSliceFlag:
|
||||||
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
return FlagEnvHinter(fv.FieldByName("EnvVar").String(),
|
||||||
stringifyIntSliceFlag(f.(IntSliceFlag)))
|
stringifyIntSliceFlag(f.(IntSliceFlag)))
|
||||||
case Int64SliceFlag:
|
case Int64SliceFlag:
|
||||||
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
return FlagEnvHinter(fv.FieldByName("EnvVar").String(),
|
||||||
stringifyInt64SliceFlag(f.(Int64SliceFlag)))
|
stringifyInt64SliceFlag(f.(Int64SliceFlag)))
|
||||||
case StringSliceFlag:
|
case StringSliceFlag:
|
||||||
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
return FlagEnvHinter(fv.FieldByName("EnvVar").String(),
|
||||||
stringifyStringSliceFlag(f.(StringSliceFlag)))
|
stringifyStringSliceFlag(f.(StringSliceFlag)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,9 +732,8 @@ func stringifyFlag(f Flag) string {
|
|||||||
|
|
||||||
needsPlaceholder := false
|
needsPlaceholder := false
|
||||||
defaultValueString := ""
|
defaultValueString := ""
|
||||||
val := fv.FieldByName("Value")
|
|
||||||
|
|
||||||
if val.IsValid() {
|
if val := fv.FieldByName("Value"); val.IsValid() {
|
||||||
needsPlaceholder = true
|
needsPlaceholder = true
|
||||||
defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface())
|
defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface())
|
||||||
|
|
||||||
@ -744,8 +752,8 @@ func stringifyFlag(f Flag) string {
|
|||||||
|
|
||||||
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString))
|
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString))
|
||||||
|
|
||||||
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
return FlagEnvHinter(fv.FieldByName("EnvVar").String(),
|
||||||
fmt.Sprintf("%s\t%s", prefixedNames(fv.FieldByName("Name").String(), placeholder), usageWithDefault))
|
fmt.Sprintf("%s\t%s", FlagNamePrefixer(fv.FieldByName("Name").String(), placeholder), usageWithDefault))
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringifyIntSliceFlag(f IntSliceFlag) string {
|
func stringifyIntSliceFlag(f IntSliceFlag) string {
|
||||||
@ -795,5 +803,5 @@ func stringifySliceFlag(usage, name string, defaultVals []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal))
|
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal))
|
||||||
return fmt.Sprintf("%s\t%s", prefixedNames(name, placeholder), usageWithDefault)
|
return fmt.Sprintf("%s\t%s", FlagNamePrefixer(name, placeholder), usageWithDefault)
|
||||||
}
|
}
|
||||||
|
13
vendor/github.com/urfave/cli/funcs.go
generated
vendored
13
vendor/github.com/urfave/cli/funcs.go
generated
vendored
@ -23,6 +23,19 @@ type CommandNotFoundFunc func(*Context, string)
|
|||||||
// is displayed and the execution is interrupted.
|
// is displayed and the execution is interrupted.
|
||||||
type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error
|
type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error
|
||||||
|
|
||||||
|
// ExitErrHandlerFunc is executed if provided in order to handle ExitError values
|
||||||
|
// returned by Actions and Before/After functions.
|
||||||
|
type ExitErrHandlerFunc func(context *Context, err error)
|
||||||
|
|
||||||
// FlagStringFunc is used by the help generation to display a flag, which is
|
// FlagStringFunc is used by the help generation to display a flag, which is
|
||||||
// expected to be a single line.
|
// expected to be a single line.
|
||||||
type FlagStringFunc func(Flag) string
|
type FlagStringFunc func(Flag) string
|
||||||
|
|
||||||
|
// FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix
|
||||||
|
// text for a flag's full name.
|
||||||
|
type FlagNamePrefixFunc func(fullName, placeholder string) string
|
||||||
|
|
||||||
|
// FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help
|
||||||
|
// with the environment variable details.
|
||||||
|
type FlagEnvHintFunc func(envVar, str string) string
|
||||||
|
|
||||||
|
63
vendor/github.com/urfave/cli/help.go
generated
vendored
63
vendor/github.com/urfave/cli/help.go
generated
vendored
@ -29,6 +29,7 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
|
|||||||
{{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}}
|
{{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}}
|
||||||
|
|
||||||
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
||||||
|
|
||||||
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
||||||
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ var CommandHelpTemplate = `NAME:
|
|||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Category}}
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
|
||||||
|
|
||||||
CATEGORY:
|
CATEGORY:
|
||||||
{{.Category}}{{end}}{{if .Description}}
|
{{.Category}}{{end}}{{if .Description}}
|
||||||
@ -67,7 +68,7 @@ var SubcommandHelpTemplate = `NAME:
|
|||||||
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
|
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
|
||||||
|
|
||||||
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
||||||
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
||||||
@ -112,17 +113,42 @@ var helpSubcommand = Command{
|
|||||||
// Prints help for the App or Command
|
// Prints help for the App or Command
|
||||||
type helpPrinter func(w io.Writer, templ string, data interface{})
|
type helpPrinter func(w io.Writer, templ string, data interface{})
|
||||||
|
|
||||||
|
// Prints help for the App or Command with custom template function.
|
||||||
|
type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{})
|
||||||
|
|
||||||
// HelpPrinter is a function that writes the help output. If not set a default
|
// HelpPrinter is a function that writes the help output. If not set a default
|
||||||
// is used. The function signature is:
|
// is used. The function signature is:
|
||||||
// func(w io.Writer, templ string, data interface{})
|
// func(w io.Writer, templ string, data interface{})
|
||||||
var HelpPrinter helpPrinter = printHelp
|
var HelpPrinter helpPrinter = printHelp
|
||||||
|
|
||||||
|
// HelpPrinterCustom is same as HelpPrinter but
|
||||||
|
// takes a custom function for template function map.
|
||||||
|
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
|
||||||
|
|
||||||
// VersionPrinter prints the version for the App
|
// VersionPrinter prints the version for the App
|
||||||
var VersionPrinter = printVersion
|
var VersionPrinter = printVersion
|
||||||
|
|
||||||
|
// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
|
||||||
|
func ShowAppHelpAndExit(c *Context, exitCode int) {
|
||||||
|
ShowAppHelp(c)
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
||||||
|
|
||||||
// ShowAppHelp is an action that displays the help.
|
// ShowAppHelp is an action that displays the help.
|
||||||
func ShowAppHelp(c *Context) error {
|
func ShowAppHelp(c *Context) (err error) {
|
||||||
|
if c.App.CustomAppHelpTemplate == "" {
|
||||||
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
customAppData := func() map[string]interface{} {
|
||||||
|
if c.App.ExtraInfo == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"ExtraInfo": c.App.ExtraInfo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +164,12 @@ func DefaultAppComplete(c *Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShowCommandHelpAndExit - exits with code after showing help
|
||||||
|
func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
||||||
|
ShowCommandHelp(c, command)
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
// ShowCommandHelp prints help for the given command
|
// ShowCommandHelp prints help for the given command
|
||||||
func ShowCommandHelp(ctx *Context, command string) error {
|
func ShowCommandHelp(ctx *Context, command string) error {
|
||||||
// show the subcommand help for a command with subcommands
|
// show the subcommand help for a command with subcommands
|
||||||
@ -148,7 +180,11 @@ func ShowCommandHelp(ctx *Context, command string) error {
|
|||||||
|
|
||||||
for _, c := range ctx.App.Commands {
|
for _, c := range ctx.App.Commands {
|
||||||
if c.HasName(command) {
|
if c.HasName(command) {
|
||||||
|
if c.CustomHelpTemplate != "" {
|
||||||
|
HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil)
|
||||||
|
} else {
|
||||||
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,10 +227,15 @@ func ShowCommandCompletions(ctx *Context, command string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printHelp(out io.Writer, templ string, data interface{}) {
|
func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) {
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"join": strings.Join,
|
"join": strings.Join,
|
||||||
}
|
}
|
||||||
|
if customFunc != nil {
|
||||||
|
for key, value := range customFunc {
|
||||||
|
funcMap[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
|
w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
|
||||||
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
||||||
@ -210,10 +251,14 @@ func printHelp(out io.Writer, templ string, data interface{}) {
|
|||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printHelp(out io.Writer, templ string, data interface{}) {
|
||||||
|
printHelpCustom(out, templ, data, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func checkVersion(c *Context) bool {
|
func checkVersion(c *Context) bool {
|
||||||
found := false
|
found := false
|
||||||
if VersionFlag.Name != "" {
|
if VersionFlag.GetName() != "" {
|
||||||
eachName(VersionFlag.Name, func(name string) {
|
eachName(VersionFlag.GetName(), func(name string) {
|
||||||
if c.GlobalBool(name) || c.Bool(name) {
|
if c.GlobalBool(name) || c.Bool(name) {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
@ -224,8 +269,8 @@ func checkVersion(c *Context) bool {
|
|||||||
|
|
||||||
func checkHelp(c *Context) bool {
|
func checkHelp(c *Context) bool {
|
||||||
found := false
|
found := false
|
||||||
if HelpFlag.Name != "" {
|
if HelpFlag.GetName() != "" {
|
||||||
eachName(HelpFlag.Name, func(name string) {
|
eachName(HelpFlag.GetName(), func(name string) {
|
||||||
if c.GlobalBool(name) || c.Bool(name) {
|
if c.GlobalBool(name) || c.Bool(name) {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
@ -260,7 +305,7 @@ func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) {
|
|||||||
pos := len(arguments) - 1
|
pos := len(arguments) - 1
|
||||||
lastArg := arguments[pos]
|
lastArg := arguments[pos]
|
||||||
|
|
||||||
if lastArg != "--"+BashCompletionFlag.Name {
|
if lastArg != "--"+BashCompletionFlag.GetName() {
|
||||||
return false, arguments
|
return false, arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user