|
|
|
@ -5,24 +5,24 @@ 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.App{}).Run(os.Args)
|
|
|
|
|
(&cli.App{}).Run(os.Args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Of course this application does not do much, so let's make this an actual
|
|
|
|
|
application:
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
app := &cli.App{
|
|
|
|
|
Name: "greet",
|
|
|
|
|
Usage: "say a greeting",
|
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
|
fmt.Println("Greetings")
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.Run(os.Args)
|
|
|
|
|
}
|
|
|
|
|
func main() {
|
|
|
|
|
app := &cli.App{
|
|
|
|
|
Name: "greet",
|
|
|
|
|
Usage: "say a greeting",
|
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
|
fmt.Println("Greetings")
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.Run(os.Args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VARIABLES
|
|
|
|
|
|
|
|
|
@ -49,8 +49,8 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
|
|
|
|
|
|
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
|
{{.Name}}:{{range .VisibleCommands}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
|
|
|
|
|
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}
|
|
|
|
|
|
|
|
|
|
GLOBAL OPTIONS:{{range .VisibleFlagCategories}}
|
|
|
|
|
{{if .Name}}{{.Name}}
|
|
|
|
@ -157,8 +157,8 @@ DESCRIPTION:
|
|
|
|
|
|
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
|
{{.Name}}:{{range .VisibleCommands}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
|
|
|
|
|
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
@ -300,6 +300,8 @@ type App struct {
|
|
|
|
|
CommandNotFound CommandNotFoundFunc
|
|
|
|
|
// Execute this function if a usage error occurs
|
|
|
|
|
OnUsageError OnUsageErrorFunc
|
|
|
|
|
// Execute this function when an invalid flag is accessed from the context
|
|
|
|
|
InvalidFlagAccessHandler InvalidFlagAccessFunc
|
|
|
|
|
// Compilation date
|
|
|
|
|
Compiled time.Time
|
|
|
|
|
// List of all authors who contributed
|
|
|
|
@ -450,6 +452,8 @@ type BoolFlag struct {
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
|
|
|
|
|
Count *int
|
|
|
|
|
}
|
|
|
|
|
BoolFlag is a flag with type bool
|
|
|
|
|
|
|
|
|
@ -629,6 +633,9 @@ func (cCtx *Context) Args() Args
|
|
|
|
|
func (cCtx *Context) Bool(name string) bool
|
|
|
|
|
Bool looks up the value of a local BoolFlag, returns false if not found
|
|
|
|
|
|
|
|
|
|
func (cCtx *Context) Count(name string) int
|
|
|
|
|
Count returns the num of occurences of this flag
|
|
|
|
|
|
|
|
|
|
func (cCtx *Context) Duration(name string) time.Duration
|
|
|
|
|
Duration looks up the value of a local DurationFlag, returns 0 if not found
|
|
|
|
|
|
|
|
|
@ -698,9 +705,23 @@ func (cCtx *Context) Uint(name string) uint
|
|
|
|
|
func (cCtx *Context) Uint64(name string) uint64
|
|
|
|
|
Uint64 looks up the value of a local Uint64Flag, returns 0 if not found
|
|
|
|
|
|
|
|
|
|
func (cCtx *Context) Uint64Slice(name string) []uint64
|
|
|
|
|
Uint64Slice looks up the value of a local Uint64SliceFlag, returns nil if
|
|
|
|
|
not found
|
|
|
|
|
|
|
|
|
|
func (cCtx *Context) UintSlice(name string) []uint
|
|
|
|
|
UintSlice looks up the value of a local UintSliceFlag, returns nil if not
|
|
|
|
|
found
|
|
|
|
|
|
|
|
|
|
func (cCtx *Context) Value(name string) interface{}
|
|
|
|
|
Value returns the value of the flag corresponding to `name`
|
|
|
|
|
|
|
|
|
|
type Countable interface {
|
|
|
|
|
Count() int
|
|
|
|
|
}
|
|
|
|
|
Countable is an interface to enable detection of flag values which support
|
|
|
|
|
repetitive flags
|
|
|
|
|
|
|
|
|
|
type DocGenerationFlag interface {
|
|
|
|
|
Flag
|
|
|
|
|
|
|
|
|
@ -1064,7 +1085,7 @@ type GenericFlag struct {
|
|
|
|
|
HasBeenSet bool
|
|
|
|
|
|
|
|
|
|
Value Generic
|
|
|
|
|
Destination *Generic
|
|
|
|
|
Destination Generic
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
@ -1073,7 +1094,7 @@ type GenericFlag struct {
|
|
|
|
|
}
|
|
|
|
|
GenericFlag is a flag with type Generic
|
|
|
|
|
|
|
|
|
|
func (f GenericFlag) Apply(set *flag.FlagSet) error
|
|
|
|
|
func (f *GenericFlag) Apply(set *flag.FlagSet) error
|
|
|
|
|
Apply takes the flagset and calls Set on the generic flag with the value
|
|
|
|
|
provided by the user for parsing by the flag
|
|
|
|
|
|
|
|
|
@ -1131,6 +1152,8 @@ type Int64Flag struct {
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
|
|
|
|
|
Base int
|
|
|
|
|
}
|
|
|
|
|
Int64Flag is a flag with type int64
|
|
|
|
|
|
|
|
|
@ -1280,6 +1303,8 @@ type IntFlag struct {
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
|
|
|
|
|
Base int
|
|
|
|
|
}
|
|
|
|
|
IntFlag is a flag with type int
|
|
|
|
|
|
|
|
|
@ -1416,6 +1441,10 @@ func (f *IntSliceFlag) String() string
|
|
|
|
|
func (f *IntSliceFlag) TakesValue() bool
|
|
|
|
|
TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
|
|
|
|
|
|
type InvalidFlagAccessFunc func(*Context, string)
|
|
|
|
|
InvalidFlagAccessFunc is executed when an invalid flag is accessed from the
|
|
|
|
|
context.
|
|
|
|
|
|
|
|
|
|
type MultiError interface {
|
|
|
|
|
error
|
|
|
|
|
Errors() []error
|
|
|
|
@ -1850,6 +1879,8 @@ type Uint64Flag struct {
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
|
|
|
|
|
Base int
|
|
|
|
|
}
|
|
|
|
|
Uint64Flag is a flag with type uint64
|
|
|
|
|
|
|
|
|
@ -1893,6 +1924,89 @@ func (f *Uint64Flag) String() string
|
|
|
|
|
func (f *Uint64Flag) TakesValue() bool
|
|
|
|
|
TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
|
|
|
|
|
|
type Uint64Slice struct {
|
|
|
|
|
// Has unexported fields.
|
|
|
|
|
}
|
|
|
|
|
Uint64Slice wraps []int64 to satisfy flag.Value
|
|
|
|
|
|
|
|
|
|
func NewUint64Slice(defaults ...uint64) *Uint64Slice
|
|
|
|
|
NewUint64Slice makes an *Uint64Slice with default values
|
|
|
|
|
|
|
|
|
|
func (i *Uint64Slice) Get() interface{}
|
|
|
|
|
Get returns the slice of ints set by this flag
|
|
|
|
|
|
|
|
|
|
func (i *Uint64Slice) Serialize() string
|
|
|
|
|
Serialize allows Uint64Slice to fulfill Serializer
|
|
|
|
|
|
|
|
|
|
func (i *Uint64Slice) Set(value string) error
|
|
|
|
|
Set parses the value into an integer and appends it to the list of values
|
|
|
|
|
|
|
|
|
|
func (i *Uint64Slice) String() string
|
|
|
|
|
String returns a readable representation of this value (for usage defaults)
|
|
|
|
|
|
|
|
|
|
func (i *Uint64Slice) Value() []uint64
|
|
|
|
|
Value returns the slice of ints set by this flag
|
|
|
|
|
|
|
|
|
|
type Uint64SliceFlag struct {
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
Category string
|
|
|
|
|
DefaultText string
|
|
|
|
|
FilePath string
|
|
|
|
|
Usage string
|
|
|
|
|
|
|
|
|
|
Required bool
|
|
|
|
|
Hidden bool
|
|
|
|
|
HasBeenSet bool
|
|
|
|
|
|
|
|
|
|
Value *Uint64Slice
|
|
|
|
|
Destination *Uint64Slice
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
}
|
|
|
|
|
Uint64SliceFlag is a flag with type *Uint64Slice
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) Apply(set *flag.FlagSet) error
|
|
|
|
|
Apply populates the flag given the flag set and environment
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) Get(ctx *Context) []uint64
|
|
|
|
|
Get returns the flag’s value in the given Context.
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) GetCategory() string
|
|
|
|
|
GetCategory returns the category for the flag
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) GetDefaultText() string
|
|
|
|
|
GetDefaultText returns the default text for this flag
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) GetEnvVars() []string
|
|
|
|
|
GetEnvVars returns the env vars for this flag
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) GetUsage() string
|
|
|
|
|
GetUsage returns the usage string for the flag
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) GetValue() string
|
|
|
|
|
GetValue returns the flags value as string representation and an empty
|
|
|
|
|
string if the flag takes no value at all.
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) IsRequired() bool
|
|
|
|
|
IsRequired returns whether or not the flag is required
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) IsSet() bool
|
|
|
|
|
IsSet returns whether or not the flag has been set through env or file
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) IsVisible() bool
|
|
|
|
|
IsVisible returns true if the flag is not hidden, otherwise false
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) Names() []string
|
|
|
|
|
Names returns the names of the flag
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) String() string
|
|
|
|
|
String returns a readable representation of this value (for usage defaults)
|
|
|
|
|
|
|
|
|
|
func (f *Uint64SliceFlag) TakesValue() bool
|
|
|
|
|
TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
|
|
|
|
|
|
type UintFlag struct {
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
@ -1910,6 +2024,8 @@ type UintFlag struct {
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
|
|
|
|
|
Base int
|
|
|
|
|
}
|
|
|
|
|
UintFlag is a flag with type uint
|
|
|
|
|
|
|
|
|
@ -1953,6 +2069,93 @@ func (f *UintFlag) String() string
|
|
|
|
|
func (f *UintFlag) TakesValue() bool
|
|
|
|
|
TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
|
|
|
|
|
|
type UintSlice struct {
|
|
|
|
|
// Has unexported fields.
|
|
|
|
|
}
|
|
|
|
|
UintSlice wraps []int to satisfy flag.Value
|
|
|
|
|
|
|
|
|
|
func NewUintSlice(defaults ...uint) *UintSlice
|
|
|
|
|
NewUintSlice makes an *UintSlice with default values
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) Get() interface{}
|
|
|
|
|
Get returns the slice of ints set by this flag
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) Serialize() string
|
|
|
|
|
Serialize allows UintSlice to fulfill Serializer
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) Set(value string) error
|
|
|
|
|
Set parses the value into an integer and appends it to the list of values
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) SetUint(value uint)
|
|
|
|
|
TODO: Consistently have specific Set function for Int64 and Float64 ? SetInt
|
|
|
|
|
directly adds an integer to the list of values
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) String() string
|
|
|
|
|
String returns a readable representation of this value (for usage defaults)
|
|
|
|
|
|
|
|
|
|
func (i *UintSlice) Value() []uint
|
|
|
|
|
Value returns the slice of ints set by this flag
|
|
|
|
|
|
|
|
|
|
type UintSliceFlag struct {
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
Category string
|
|
|
|
|
DefaultText string
|
|
|
|
|
FilePath string
|
|
|
|
|
Usage string
|
|
|
|
|
|
|
|
|
|
Required bool
|
|
|
|
|
Hidden bool
|
|
|
|
|
HasBeenSet bool
|
|
|
|
|
|
|
|
|
|
Value *UintSlice
|
|
|
|
|
Destination *UintSlice
|
|
|
|
|
|
|
|
|
|
Aliases []string
|
|
|
|
|
EnvVars []string
|
|
|
|
|
}
|
|
|
|
|
UintSliceFlag is a flag with type *UintSlice
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) Apply(set *flag.FlagSet) error
|
|
|
|
|
Apply populates the flag given the flag set and environment
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) Get(ctx *Context) []uint
|
|
|
|
|
Get returns the flag’s value in the given Context.
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) GetCategory() string
|
|
|
|
|
GetCategory returns the category for the flag
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) GetDefaultText() string
|
|
|
|
|
GetDefaultText returns the default text for this flag
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) GetEnvVars() []string
|
|
|
|
|
GetEnvVars returns the env vars for this flag
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) GetUsage() string
|
|
|
|
|
GetUsage returns the usage string for the flag
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) GetValue() string
|
|
|
|
|
GetValue returns the flags value as string representation and an empty
|
|
|
|
|
string if the flag takes no value at all.
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) IsRequired() bool
|
|
|
|
|
IsRequired returns whether or not the flag is required
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) IsSet() bool
|
|
|
|
|
IsSet returns whether or not the flag has been set through env or file
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) IsVisible() bool
|
|
|
|
|
IsVisible returns true if the flag is not hidden, otherwise false
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) Names() []string
|
|
|
|
|
Names returns the names of the flag
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) String() string
|
|
|
|
|
String returns a readable representation of this value (for usage defaults)
|
|
|
|
|
|
|
|
|
|
func (f *UintSliceFlag) TakesValue() bool
|
|
|
|
|
TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
|
|
|
|
|
|
type VisibleFlag interface {
|
|
|
|
|
Flag
|
|
|
|
|
|
|
|
|
|