// List of all authors who contributed · pkg.go.dev

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)
}

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.

View Source

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.

View Source

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 DefaultCompleteWithFlags(cmd *Command) func(c *Context)

func HandleAction added in v1.15.0

func HandleAction(action interface{}, context *Context) (err error)

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

func ShowAppHelpAndExit(c *Context, exitCode int)

ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.

func ShowCommandCompletions added in v1.1.0

func ShowCommandCompletions(ctx *Context, command string)

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

func ShowCommandHelpAndExit(c *Context, command string, code int)

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

func ShowSubcommandHelp(c *Context) error

ShowSubcommandHelp prints help for the given subcommand

func ShowVersion(c *Context)

ShowVersion prints the version number of the App

type ActionFunc func(*Context) error

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

func (a *App) RunAsSubcommand(ctx *Context) (err error)

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

func (a *App) VisibleCommands() []Command

VisibleCommands returns a slice of the Commands with Hidden=false

func (a *App) VisibleFlags() []Flag

VisibleFlags returns a slice of the Flags 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

func (a Args) Present() bool

Present checks if there are any arguments present

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

type BeforeFunc func(*Context) error

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.

func (f BoolFlag) IsRequired() bool

IsRequired returns whether or not the flag is required

String returns a readable representation of this value (for usage defaults)

func (f BoolFlag) TakesValue() bool

TakesValue returns true of the flag takes a value, otherwise false

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.

func (f BoolTFlag) IsRequired() bool

IsRequired returns whether or not the flag is required

String returns a readable representation of this value (for usage defaults)

func (f BoolTFlag) TakesValue() bool

TakesValue returns true of the flag takes a value, otherwise false

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) Names added in v1.6.0

Names returns the names including short names and aliases.

func (Command) Run

func (c Command) Run(ctx *Context) (err error)

Run invokes the command given the context, parses ctx.Args() to generate command-specific flags

func (Command) VisibleFlags added in v1.16.0

func (c Command) VisibleFlags() []Flag

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) Len added in v1.14.0

func (CommandCategories) Less added in v1.14.0

func (CommandCategories) Swap added in v1.14.0

func (c CommandCategories) Swap(i, j int)

type CommandCategory added in v1.14.0

type CommandCategory struct {
	Name     string
	Commands Commands
}

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

type CommandNotFoundFunc func(*Context, string)

CommandNotFoundFunc is executed if the proper command cannot be found

type Commands added in v1.14.0

Commands is a slice of Command

type CommandsByName added in v1.20.0

type CommandsByName []Command

func (CommandsByName) Len added in v1.20.0

func (CommandsByName) Less added in v1.20.0

func (CommandsByName) Swap added in v1.20.0

func (c CommandsByName) Swap(i, j int)
type Context struct {
	App     *App
	Command Command

}

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.

func (c *Context) Args() Args

Args returns the command line arguments associated with the context.

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

func (c *Context) FlagNames() (names []string)

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

func (c *Context) Generic(name string) interface{}

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

func (c *Context) GlobalFlagNames() (names []string)

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

func (c *Context) GlobalGeneric(name string) interface{}

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

func (c *Context) NArg() int

NArg returns the number of the command line arguments.

func (c *Context) NumFlags() int

NumFlags returns the number of flags set

func (c *Context) Parent() *Context

Parent returns the parent context, if any

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

type DocGenerationFlag interface {
	Flag

	TakesValue() bool

	GetUsage() string


	GetValue() string
}

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

type ErrorFormatter interface {
	Format(s fmt.State, verb rune)
}
type ExitCoder interface {
	error
	ExitCode() int
}

ExitCoder is the interface checked by `App` and `Command` for a custom exit code

type ExitErrHandlerFunc added in v1.21.0

type ExitErrHandlerFunc func(context *Context, err error)

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`

func NewExitError(message interface{}, exitCode int) *ExitError

NewExitError makes a new *ExitError

Error returns the string message, fulfilling the interface required by `error`

func (ee *ExitError) ExitCode() int

ExitCode returns the exit code, fulfilling the interface required by `ExitCoder`

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.

var BashCompletionFlag Flag = BoolFlag{
	Name:   "generate-bash-completion",
	Hidden: true,
}

BashCompletionFlag enables bash-completion for all commands and subcommands

var HelpFlag Flag = BoolFlag{
	Name:  "help, h",
	Usage: "show help",
}

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)

var VersionFlag Flag = BoolFlag{
	Name:  "version, v",
	Usage: "print the version",
}

VersionFlag prints the version for the application

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.

type FlagNamePrefixFunc func(fullName, placeholder string) string

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.

type FlagStringFunc func(Flag) string

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.

func (f Int64Flag) IsRequired() bool

IsRequired returns whether or not the flag is required

String returns a readable representation of this value (for usage defaults)

func (f Int64Flag) TakesValue() bool

TakesValue returns true of the flag takes a value, otherwise false

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.

func (f IntFlag) IsRequired() bool

IsRequired returns whether or not the flag is required

String returns a readable representation of this value (for usage defaults)

func (f IntFlag) TakesValue() bool

TakesValue returns true of the flag takes a value, otherwise false

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)

func (f *IntSlice) Value() []int

Value returns the slice of ints set by this flag

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.

type RequiredFlag interface {
	Flag
	IsRequired() bool
}

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.

func (f UintFlag) IsRequired() bool

IsRequired returns whether or not the flag is required

String returns a readable representation of this value (for usage defaults)

func (f UintFlag) TakesValue() bool

TakesValue returns true of the flag takes a value, otherwise false

Read the original on pkg.go.dev ↗