Package cli provides a minimal framework for creating and organizing command line Go applications. cli is designed to be easy to understand and write, the most simple cli application can be written as follows:
func main() {
cli.NewApp().Run(os.Args)
}
Of course this application does not do much, so let's make this an actual application:
func main() {
app := cli.NewApp()
app.Name = "greet"
app.Usage = "say a greeting"
app.Action = func(c *cli.Context) error {
println("Greetings")
return nil
}
app.Run(os.Args)
}
- Variables
- func DefaultAppComplete(c *Context)
- func DefaultCompleteWithFlags(cmd *Command) func(c *Context)
- func HandleAction(action interface{}, context *Context) (err error)
- func HandleExitCoder(err error)
- func ShowAppHelp(c *Context) error
- func ShowAppHelpAndExit(c *Context, exitCode int)
- func ShowCommandCompletions(ctx *Context, command string)
- func ShowCommandHelp(ctx *Context, command string) error
- func ShowCommandHelpAndExit(c *Context, command string, code int)
- func ShowCompletions(c *Context)
- func ShowSubcommandHelp(c *Context) error
- func ShowVersion(c *Context)
- type ActionFunc
- type AfterFunc
- type App
- func (a *App) Categories() CommandCategories
- func (a *App) Command(name string) *Command
- func (a *App) Run(arguments []string) (err error)
- func (a *App) RunAndExitOnError()deprecated
- func (a *App) RunAsSubcommand(ctx *Context) (err error)
- func (a *App) Setup()
- func (a *App) ToFishCompletion() (string, error)
- func (a *App) ToMan() (string, error)
- func (a *App) ToMarkdown() (string, error)
- func (a *App) VisibleCategories() []*CommandCategory
- func (a *App) VisibleCommands() []Command
- func (a *App) VisibleFlags() []Flag
- type Args
- type Author
- type BashCompleteFunc
- type BeforeFunc
- type BoolFlag
- func (f BoolFlag) Apply(set *flag.FlagSet)
- func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error
- func (f BoolFlag) GetName() string
- func (f BoolFlag) GetUsage() string
- func (f BoolFlag) GetValue() string
- func (f BoolFlag) IsRequired() bool
- func (f BoolFlag) String() string
- func (f BoolFlag) TakesValue() bool
- type BoolTFlag
- func (f BoolTFlag) Apply(set *flag.FlagSet)
- func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error
- func (f BoolTFlag) GetName() string
- func (f BoolTFlag) GetUsage() string
- func (f BoolTFlag) GetValue() string
- func (f BoolTFlag) IsRequired() bool
- func (f BoolTFlag) String() string
- func (f BoolTFlag) TakesValue() bool
- type Command
- type CommandCategories
- type CommandCategory
- type CommandNotFoundFunc
- type Commands
- type CommandsByName
- type Context
- func (c *Context) Args() Args
- func (c *Context) Bool(name string) bool
- func (c *Context) BoolT(name string) bool
- func (c *Context) Duration(name string) time.Duration
- func (c *Context) FlagNames() (names []string)
- func (c *Context) Float64(name string) float64
- func (c *Context) Generic(name string) interface{}
- func (c *Context) GlobalBool(name string) bool
- func (c *Context) GlobalBoolT(name string) bool
- func (c *Context) GlobalDuration(name string) time.Duration
- func (c *Context) GlobalFlagNames() (names []string)
- func (c *Context) GlobalFloat64(name string) float64
- func (c *Context) GlobalGeneric(name string) interface{}
- func (c *Context) GlobalInt(name string) int
- func (c *Context) GlobalInt64(name string) int64
- func (c *Context) GlobalInt64Slice(name string) []int64
- func (c *Context) GlobalIntSlice(name string) []int
- func (c *Context) GlobalIsSet(name string) bool
- func (c *Context) GlobalSet(name, value string) error
- func (c *Context) GlobalString(name string) string
- func (c *Context) GlobalStringSlice(name string) []string
- func (c *Context) GlobalUint(name string) uint
- func (c *Context) GlobalUint64(name string) uint64
- func (c *Context) Int(name string) int
- func (c *Context) Int64(name string) int64
- func (c *Context) Int64Slice(name string) []int64
- func (c *Context) IntSlice(name string) []int
- func (c *Context) IsSet(name string) bool
- func (c *Context) NArg() int
- func (c *Context) NumFlags() int
- func (c *Context) Parent() *Context
- func (c *Context) Set(name, value string) error
- func (c *Context) String(name string) string
- func (c *Context) StringSlice(name string) []string
- func (c *Context) Uint(name string) uint
- func (c *Context) Uint64(name string) uint64
- type DocGenerationFlag
- type DurationFlag
- func (f DurationFlag) Apply(set *flag.FlagSet)
- func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error
- func (f DurationFlag) GetName() string
- func (f DurationFlag) GetUsage() string
- func (f DurationFlag) GetValue() string
- func (f DurationFlag) IsRequired() bool
- func (f DurationFlag) String() string
- func (f DurationFlag) TakesValue() bool
- type ErrorFormatter
- type ExitCoder
- type ExitErrHandlerFunc
- type ExitError
- type Flag
- type FlagEnvHintFunc
- type FlagFileHintFunc
- type FlagNamePrefixFunc
- type FlagStringFunc
- type FlagsByName
- type Float64Flag
- func (f Float64Flag) Apply(set *flag.FlagSet)
- func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error
- func (f Float64Flag) GetName() string
- func (f Float64Flag) GetUsage() string
- func (f Float64Flag) GetValue() string
- func (f Float64Flag) IsRequired() bool
- func (f Float64Flag) String() string
- func (f Float64Flag) TakesValue() bool
- type Generic
- type GenericFlag
- func (f GenericFlag) Apply(set *flag.FlagSet)
- func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error
- func (f GenericFlag) GetName() string
- func (f GenericFlag) GetUsage() string
- func (f GenericFlag) GetValue() string
- func (f GenericFlag) IsRequired() bool
- func (f GenericFlag) String() string
- func (f GenericFlag) TakesValue() bool
- type Int64Flag
- func (f Int64Flag) Apply(set *flag.FlagSet)
- func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error
- func (f Int64Flag) GetName() string
- func (f Int64Flag) GetUsage() string
- func (f Int64Flag) GetValue() string
- func (f Int64Flag) IsRequired() bool
- func (f Int64Flag) String() string
- func (f Int64Flag) TakesValue() bool
- type Int64Slice
- type Int64SliceFlag
- func (f Int64SliceFlag) Apply(set *flag.FlagSet)
- func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error
- func (f Int64SliceFlag) GetName() string
- func (f Int64SliceFlag) GetUsage() string
- func (f Int64SliceFlag) GetValue() string
- func (f Int64SliceFlag) IsRequired() bool
- func (f Int64SliceFlag) String() string
- func (f Int64SliceFlag) TakesValue() bool
- type IntFlag
- func (f IntFlag) Apply(set *flag.FlagSet)
- func (f IntFlag) ApplyWithError(set *flag.FlagSet) error
- func (f IntFlag) GetName() string
- func (f IntFlag) GetUsage() string
- func (f IntFlag) GetValue() string
- func (f IntFlag) IsRequired() bool
- func (f IntFlag) String() string
- func (f IntFlag) TakesValue() bool
- type IntSlice
- type IntSliceFlag
- func (f IntSliceFlag) Apply(set *flag.FlagSet)
- func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error
- func (f IntSliceFlag) GetName() string
- func (f IntSliceFlag) GetUsage() string
- func (f IntSliceFlag) GetValue() string
- func (f IntSliceFlag) IsRequired() bool
- func (f IntSliceFlag) String() string
- func (f IntSliceFlag) TakesValue() bool
- type MultiError
- type OnUsageErrorFunc
- type RequiredFlag
- type StringFlag
- func (f StringFlag) Apply(set *flag.FlagSet)
- func (f StringFlag) ApplyWithError(set *flag.FlagSet) error
- func (f StringFlag) GetName() string
- func (f StringFlag) GetUsage() string
- func (f StringFlag) GetValue() string
- func (f StringFlag) IsRequired() bool
- func (f StringFlag) String() string
- func (f StringFlag) TakesValue() bool
- type StringSlice
- type StringSliceFlag
- func (f StringSliceFlag) Apply(set *flag.FlagSet)
- func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error
- func (f StringSliceFlag) GetName() string
- func (f StringSliceFlag) GetUsage() string
- func (f StringSliceFlag) GetValue() string
- func (f StringSliceFlag) IsRequired() bool
- func (f StringSliceFlag) String() string
- func (f StringSliceFlag) TakesValue() bool
- type Uint64Flag
- func (f Uint64Flag) Apply(set *flag.FlagSet)
- func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error
- func (f Uint64Flag) GetName() string
- func (f Uint64Flag) GetUsage() string
- func (f Uint64Flag) GetValue() string
- func (f Uint64Flag) IsRequired() bool
- func (f Uint64Flag) String() string
- func (f Uint64Flag) TakesValue() bool
- type UintFlag
- func (f UintFlag) Apply(set *flag.FlagSet)
- func (f UintFlag) ApplyWithError(set *flag.FlagSet) error
- func (f UintFlag) GetName() string
- func (f UintFlag) GetUsage() string
- func (f UintFlag) GetValue() string
- func (f UintFlag) IsRequired() bool
- func (f UintFlag) String() string
- func (f UintFlag) TakesValue() bool
This section is empty.
AppHelpTemplate is the text template for the Default help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.
CommandHelpTemplate is 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.
ErrWriter is used to write errors to the user. This can be anything implementing the io.Writer interface and defaults to os.Stderr.
HelpPrinter is a function that writes the help output. If not set explicitly, this calls HelpPrinterCustom using only the default template functions.
If custom logic for printing help is required, this function can be overridden. If the ExtraInfo field is defined on an App, this function should not be modified, as HelpPrinterCustom will be used directly in order to capture the extra information.
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
HelpPrinterCustom is a function that writes the help output. It is used as the default implementation of HelpPrinter, and may be called directly if the ExtraInfo field is set on an App.
var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }}
% {{ .App.Author }}
# NAME
{{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }}
# SYNOPSIS
{{ .App.Name }}
{{ if .SynopsisArgs }}
` + "```" + `
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
{{ end }}{{ if .App.UsageText }}
# DESCRIPTION
{{ .App.UsageText }}
{{ end }}
**Usage**:
` + "```" + `
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
` + "```" + `
{{ if .GlobalArgs }}
# GLOBAL OPTIONS
{{ range $v := .GlobalArgs }}
{{ $v }}{{ end }}
{{ end }}{{ if .Commands }}
# COMMANDS
{{ range $v := .Commands }}
{{ $v }}{{ end }}{{ end }}`
OsExiter is the function used when the app exits. If not set defaults to os.Exit.
SubcommandHelpTemplate is the text template for the subcommand help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.
VersionPrinter prints the version for the App
func DefaultAppComplete(c *Context)
DefaultAppComplete prints the list of subcommands as the default app completion method
func HandleAction ¶ added in v1.15.0
HandleAction attempts to figure out which Action signature was used. If it's an ActionFunc or a func with the legacy signature for Action, the func is run!
func HandleExitCoder ¶ added in v1.15.0
func HandleExitCoder(err error)
HandleExitCoder checks if the error fulfills the ExitCoder interface, and if so prints the error to stderr (if it is non-empty) and calls OsExiter with the given exit code. If the given error is a MultiError, then this func is called on all members of the Errors slice and calls OsExiter with the last exit code.
ShowAppHelp is an action that displays the help.
func ShowAppHelpAndExit ¶ added in v1.20.0
ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
func ShowCommandCompletions ¶ added in v1.1.0
ShowCommandCompletions prints the custom completions for a given command
func ShowCommandHelp ¶ added in v1.0.0
ShowCommandHelp prints help for the given command
func ShowCommandHelpAndExit ¶ added in v1.20.0
ShowCommandHelpAndExit - exits with code after showing help
func ShowCompletions(c *Context)
ShowCompletions prints the lists of commands within a given context
func ShowSubcommandHelp ¶ added in v1.1.0
ShowSubcommandHelp prints help for the given subcommand
func ShowVersion(c *Context)
ShowVersion prints the version number of the App
ActionFunc is the action to execute when no subcommands are specified
AfterFunc is an action to execute after any subcommands are run, but after the subcommand has finished it is run even if Action() panics
App is the main structure of a cli application. It is recommended that an app be created with the cli.NewApp() function
NewApp creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
func (a *App) Categories() CommandCategories
Categories returns a slice containing all the categories with the commands they contain
func (*App) Command ¶ added in v1.0.0
Command returns the named command on App. Returns nil if the command does not exist
Run is the entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
// set args for examples sake
os.Args = []string{"greet", "--name", "Jeremy"}
app := NewApp()
app.Name = "greet"
app.Flags = []Flag{
StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
}
app.Action = func(c *Context) error {
fmt.Printf("Hello %v\n", c.String("name"))
return nil
}
app.UsageText = "app [first_arg] [second_arg]"
app.Author = "Harrison"
app.Email = "harrison@lolwut.com"
app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
_ = app.Run(os.Args)
Output: Hello Jeremy
// set args for examples sake
os.Args = []string{"greet", "help"}
app := NewApp()
app.Name = "greet"
app.Version = "0.1.0"
app.Description = "This is how we describe greet the app"
app.Authors = []Author{
{Name: "Harrison", Email: "harrison@lolwut.com"},
{Name: "Oliver Allen", Email: "oliver@toyshop.com"},
}
app.Flags = []Flag{
StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
}
app.Commands = []Command{
{
Name: "describeit",
Aliases: []string{"d"},
Usage: "use it to see a description",
Description: "This is how we describe describeit the function",
Action: func(c *Context) error {
fmt.Printf("i like to describe things")
return nil
},
},
}
_ = app.Run(os.Args)
Output: NAME: greet - A new cli application USAGE: greet [global options] command [command options] [arguments...] VERSION: 0.1.0 DESCRIPTION: This is how we describe greet the app AUTHORS: Harrison <harrison@lolwut.com> Oliver Allen <oliver@toyshop.com> COMMANDS: describeit, d use it to see a description help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --name value a name to say (default: "bob") --help, -h show help --version, -v print the version
// set args for examples sake
os.Args = []string{"greet", "--generate-bash-completion"}
app := NewApp()
app.Name = "greet"
app.EnableBashCompletion = true
app.Commands = []Command{
{
Name: "describeit",
Aliases: []string{"d"},
Usage: "use it to see a description",
Description: "This is how we describe describeit the function",
Action: func(c *Context) error {
fmt.Printf("i like to describe things")
return nil
},
}, {
Name: "next",
Usage: "next example",
Description: "more stuff to see when generating bash completion",
Action: func(c *Context) error {
fmt.Printf("the next example")
return nil
},
},
}
_ = app.Run(os.Args)
Output: describeit d next help h
os.Args = []string{"greet", "--s", "--generate-bash-completion"}
app := NewApp()
app.Name = "greet"
app.EnableBashCompletion = true
app.Flags = []Flag{
IntFlag{
Name: "other,o",
},
StringFlag{
Name: "xyz,x",
},
StringFlag{
Name: "some-flag,s",
},
StringFlag{
Name: "similar-flag",
},
}
_ = app.Run(os.Args)
Output: --some-flag --similar-flag
os.Args = []string{"greet", "--st", "--generate-bash-completion"}
app := NewApp()
app.Name = "greet"
app.EnableBashCompletion = true
app.Flags = []Flag{
IntFlag{
Name: "int-flag,i",
},
StringFlag{
Name: "string,s",
},
StringFlag{
Name: "string-flag-2",
},
StringFlag{
Name: "similar-flag",
},
StringFlag{
Name: "some-flag",
},
}
_ = app.Run(os.Args)
Output: --string --string-flag-2
os.Args = []string{"greet", "-", "--generate-bash-completion"}
app := NewApp()
app.Name = "greet"
app.EnableBashCompletion = true
app.Flags = []Flag{
IntFlag{
Name: "other,o",
},
StringFlag{
Name: "xyz,x",
},
}
_ = app.Run(os.Args)
Output: --other -o --xyz -x --help -h
// set args for examples sake
os.Args = []string{"greet", "h", "describeit"}
app := NewApp()
app.Name = "greet"
app.Flags = []Flag{
StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
}
app.Commands = []Command{
{
Name: "describeit",
Aliases: []string{"d"},
Usage: "use it to see a description",
Description: "This is how we describe describeit the function",
Action: func(c *Context) error {
fmt.Printf("i like to describe things")
return nil
},
},
}
_ = app.Run(os.Args)
Output: NAME: greet describeit - use it to see a description USAGE: greet describeit [arguments...] DESCRIPTION: This is how we describe describeit the function
app := App{}
app.Name = "greet"
_ = app.Run([]string{"greet"})
Output: NAME: greet USAGE: [global options] command [command options] [arguments...] COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --help, -h show help
// set args for examples sake
os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
app := NewApp()
app.Name = "say"
app.Commands = []Command{
{
Name: "hello",
Aliases: []string{"hi"},
Usage: "use it to see a description",
Description: "This is how we describe hello the function",
Subcommands: []Command{
{
Name: "english",
Aliases: []string{"en"},
Usage: "sends a greeting in english",
Description: "greets someone in english",
Flags: []Flag{
StringFlag{
Name: "name",
Value: "Bob",
Usage: "Name of the person to greet",
},
},
Action: func(c *Context) error {
fmt.Println("Hello,", c.String("name"))
return nil
},
},
},
},
}
_ = app.Run(os.Args)
Output: Hello, Jeremy
app := App{}
app.Name = "greet"
app.Commands = []Command{
{
Name: "describeit",
Aliases: []string{"d"},
Usage: "use it to see a description",
Description: "This is how we describe describeit the function",
},
}
_ = app.Run([]string{"greet", "describeit"})
Output: NAME: describeit - use it to see a description USAGE: describeit [arguments...] DESCRIPTION: This is how we describe describeit the function
// set args for examples sake
os.Args = []string{"greet", "--generate-bash-completion"}
_ = os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1")
app := NewApp()
app.Name = "greet"
app.EnableBashCompletion = true
app.Commands = []Command{
{
Name: "describeit",
Aliases: []string{"d"},
Usage: "use it to see a description",
Description: "This is how we describe describeit the function",
Action: func(c *Context) error {
fmt.Printf("i like to describe things")
return nil
},
}, {
Name: "next",
Usage: "next example",
Description: "more stuff to see when generating bash completion",
Action: func(c *Context) error {
fmt.Printf("the next example")
return nil
},
},
}
_ = app.Run(os.Args)
Output: describeit:use it to see a description d:use it to see a description next:next example help:Shows a list of commands or help for one command h:Shows a list of commands or help for one command
func (*App) RunAndExitOnError deprecated added in v1.1.0
func (a *App) RunAndExitOnError()
RunAndExitOnError calls .Run() and exits non-zero if an error was returned
Deprecated: instead you should return an error that fulfills cli.ExitCoder to cli.App.Run. This will cause the application to exit with the given eror code in the cli.ExitCoder
func (*App) RunAsSubcommand ¶ added in v1.1.0
RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags
Setup runs initialization code to ensure all data structures are ready for `Run` or inspection prior to `Run`. It is internally called by `Run`, but will return early if setup has already happened.
ToFishCompletion creates a fish completion string for the `*App` The function errors if either parsing or writing of the string fails.
ToMan creates a man page string for the `*App` The function errors if either parsing or writing of the string fails.
ToMarkdown creates a markdown string for the `*App` The function errors if either parsing or writing of the string fails.
func (a *App) VisibleCategories() []*CommandCategory
VisibleCategories returns a slice of categories and commands that are Hidden=false
func (*App) VisibleCommands ¶ added in v1.17.0
VisibleCommands returns a slice of the Commands with Hidden=false
Args contains apps console arguments
First returns the first argument, or else a blank string
Get returns the nth argument, or else a blank string
Swap swaps arguments at the given indexes
Tail returns the rest of the arguments (not the first one) or else an empty string slice
Author represents someone who has contributed to a cli project.
String makes Author comply to the Stringer interface, to allow an easy print in the templating process
type BashCompleteFunc func(*Context)
BashCompleteFunc is an action to execute when the bash-completion flag is set
BeforeFunc is an action to execute before any subcommands are run, but after the context is ready if a non-nil error is returned, no subcommands are run
BoolFlag is a flag with type bool
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
String returns a readable representation of this value (for usage defaults)
BoolTFlag is a flag with type bool that is true by default
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
String returns a readable representation of this value (for usage defaults)
type Command ¶
Command is a subcommand for a cli.App.
func (Command) FullName ¶ added in v1.9.0
FullName returns the full name of the command. For subcommands this ensures that parent commands are part of the command path
func (Command) HasName ¶
HasName returns true if Command.Name or Command.ShortName matches given name
func (Command) Run ¶
Run invokes the command given the context, parses ctx.Args() to generate command-specific flags
func (Command) VisibleFlags ¶ added in v1.16.0
VisibleFlags returns a slice of the Flags with Hidden=false
type CommandCategories ¶ added in v1.14.0
type CommandCategories []*CommandCategory
CommandCategories is a slice of *CommandCategory.
func (CommandCategories) AddCommand ¶ added in v1.14.0
AddCommand adds a command to a category.
func (CommandCategories) Swap ¶ added in v1.14.0
func (c CommandCategories) Swap(i, j int)
type CommandCategory ¶ added in v1.14.0
CommandCategory is a category containing commands.
func (*CommandCategory) VisibleCommands ¶ added in v1.17.0
func (c *CommandCategory) VisibleCommands() []Command
VisibleCommands returns a slice of the Commands with Hidden=false
type CommandNotFoundFunc ¶ added in v1.15.0
CommandNotFoundFunc is executed if the proper command cannot be found
type CommandsByName ¶ added in v1.20.0
type CommandsByName []Command
func (CommandsByName) Swap ¶ added in v1.20.0
func (c CommandsByName) Swap(i, j int)
Context is a type that is passed through to each Handler action in a cli application. Context can be used to retrieve context-specific Args and parsed command-line options.
NewContext creates a new context. For use in when invoking an App or Command action.
Bool looks up the value of a local BoolFlag, returns false if not found
BoolT looks up the value of a local BoolTFlag, returns false if not found
Duration looks up the value of a local DurationFlag, returns 0 if not found
FlagNames returns a slice of flag names used in this context.
Float64 looks up the value of a local Float64Flag, returns 0 if not found
Generic looks up the value of a local GenericFlag, returns nil if not found
GlobalBool looks up the value of a global BoolFlag, returns false if not found
GlobalBoolT looks up the value of a global BoolTFlag, returns false if not found
GlobalDuration looks up the value of a global DurationFlag, returns 0 if not found
GlobalFlagNames returns a slice of global flag names used by the app.
GlobalFloat64 looks up the value of a global Float64Flag, returns 0 if not found
GlobalGeneric looks up the value of a global GenericFlag, returns nil if not found
GlobalInt looks up the value of a global IntFlag, returns 0 if not found
GlobalInt64 looks up the value of a global Int64Flag, returns 0 if not found
GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns nil if not found
GlobalIntSlice looks up the value of a global IntSliceFlag, returns nil if not found
GlobalIsSet determines if the global flag was actually set
GlobalSet sets a context flag to a value on the global flagset
GlobalString looks up the value of a global StringFlag, returns "" if not found
GlobalStringSlice looks up the value of a global StringSliceFlag, returns nil if not found
GlobalUint looks up the value of a global UintFlag, returns 0 if not found
GlobalUint64 looks up the value of a global Uint64Flag, returns 0 if not found
Int looks up the value of a local IntFlag, returns 0 if not found
Int64 looks up the value of a local Int64Flag, returns 0 if not found
Int64Slice looks up the value of a local Int64SliceFlag, returns nil if not found
IntSlice looks up the value of a local IntSliceFlag, returns nil if not found
IsSet determines if the flag was actually set
Set sets a context flag to a value.
String looks up the value of a local StringFlag, returns "" if not found
StringSlice looks up the value of a local StringSliceFlag, returns nil if not found
Uint looks up the value of a local UintFlag, returns 0 if not found
Uint64 looks up the value of a local Uint64Flag, returns 0 if not found
DocGenerationFlag is an interface that allows documentation generation for the flag
DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration)
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f DurationFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f DurationFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
ExitCoder is the interface checked by `App` and `Command` for a custom exit code
type ExitErrHandlerFunc ¶ added in v1.21.0
ExitErrHandlerFunc is executed if provided in order to handle ExitError values returned by Actions and Before/After functions.
type ExitError struct {
}
ExitError fulfills both the builtin `error` interface and `ExitCoder`
Error returns the string message, fulfilling the interface required by `error`
Flag is a common interface related to parsing flags in cli. For more advanced flag parsing techniques, it is recommended that this interface be implemented.
BashCompletionFlag enables bash-completion 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 unless HideHelp is set to true)
FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help with the environment variable details.
var FlagEnvHinter FlagEnvHintFunc = withEnvHint
FlagEnvHinter annotates flag help message with the environment variable details. This is used by the default FlagStringer.
FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help with the file path details.
var FlagFileHinter FlagFileHintFunc = withFileHint
FlagFileHinter annotates flag help message with the environment variable details. This is used by the default FlagStringer.
FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix text for a flag's full name.
var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames
FlagNamePrefixer converts a full flag name and its placeholder into the help message flag prefix. This is used by the default FlagStringer.
FlagStringFunc is used by the help generation to display a flag, which is expected to be a single line.
var FlagStringer FlagStringFunc = stringifyFlag
FlagStringer converts a flag definition to a string. This is used by help to display a flag.
FlagsByName is a slice of Flag.
func (f FlagsByName) Swap(i, j int)
Float64Flag is a flag with type float64
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f Float64Flag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f Float64Flag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
Generic is a generic parseable type identified by a specific flag
GenericFlag is a flag with type Generic
Apply takes the flagset and calls Set on the generic flag with the value provided by the user for parsing by the flag Ignores parsing errors
ApplyWithError takes the flagset and calls Set on the generic flag with the value provided by the user for parsing by the flag
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f GenericFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f GenericFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
Int64Flag is a flag with type int64
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
String returns a readable representation of this value (for usage defaults)
Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter
func (f *Int64Slice) Get() interface{}
Get returns the slice of ints set by this flag
Set parses the value into an integer and appends it to the list of values
String returns a readable representation of this value (for usage defaults)
Value returns the slice of ints set by this flag
Int64SliceFlag is a flag with type *Int64Slice
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f Int64SliceFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f Int64SliceFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
IntFlag is a flag with type int
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
String returns a readable representation of this value (for usage defaults)
IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter
func (f *IntSlice) Get() interface{}
Get returns the slice of ints set by this flag
Set parses the value into an integer and appends it to the list of values
String returns a readable representation of this value (for usage defaults)
IntSliceFlag is a flag with type *IntSlice
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f IntSliceFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f IntSliceFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
type MultiError struct {
Errors []error
}
MultiError is an error that wraps multiple errors.
func NewMultiError(err ...error) MultiError
NewMultiError creates a new MultiError. Pass in one or more errors.
Error implements the error interface.
OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying customized usage error messages. This function is able to replace the original error messages. If this function is not set, the "Incorrect usage" is displayed and the execution is interrupted.
RequiredFlag is an interface that allows us to mark flags as required it allows flags required flags to be backwards compatible with the Flag interface
StringFlag is a flag with type string
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f StringFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f StringFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter
func (f *StringSlice) Get() interface{}
Get returns the slice of strings set by this flag
Set appends the string value to the list of values
String returns a readable representation of this value (for usage defaults)
Value returns the slice of strings set by this flag
StringSliceFlag is a flag with type *StringSlice
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
TakesValue returns true of the flag takes a value, otherwise false
Uint64Flag is a flag with type uint64
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
func (f Uint64Flag) IsRequired() bool
IsRequired returns whether or not the flag is required
String returns a readable representation of this value (for usage defaults)
func (f Uint64Flag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false
UintFlag is a flag with type uint
Apply populates the flag given the flag set and environment Ignores errors
ApplyWithError populates the flag given the flag set and environment
GetName returns the name of the flag
GetUsage returns the usage string for the flag
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all.
String returns a readable representation of this value (for usage defaults)