@ -13,6 +13,7 @@ import (
// This flag enables bash-completion for all commands and subcommands
var BashCompletionFlag = BoolFlag {
Name : "generate-bash-completion" ,
Hide : true ,
}
// This flag prints the version for the application
@ -37,6 +38,7 @@ type Flag interface {
// Apply Flag settings to the given flag set
Apply ( * flag . FlagSet )
GetName ( ) string
isNotHidden ( ) bool
}
func flagSet ( name string , flags [ ] Flag ) * flag . FlagSet {
@ -68,6 +70,7 @@ type GenericFlag struct {
Value Generic
Usage string
EnvVar string
Hide bool
}
// String returns the string representation of the generic flag to display the
@ -112,6 +115,10 @@ func (f GenericFlag) GetName() string {
return f . Name
}
func ( f GenericFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// StringSlice is an opaque type for []string to satisfy flag.Value
type StringSlice [ ] string
@ -138,6 +145,7 @@ type StringSliceFlag struct {
Value * StringSlice
Usage string
EnvVar string
Hide bool
}
// String returns the usage
@ -177,6 +185,10 @@ func (f StringSliceFlag) GetName() string {
return f . Name
}
func ( f StringSliceFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// StringSlice is an opaque type for []int to satisfy flag.Value
type IntSlice [ ] int
@ -208,6 +220,7 @@ type IntSliceFlag struct {
Value * IntSlice
Usage string
EnvVar string
Hide bool
}
// String returns the usage
@ -250,12 +263,17 @@ func (f IntSliceFlag) GetName() string {
return f . Name
}
func ( f IntSliceFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// BoolFlag is a switch that defaults to false
type BoolFlag struct {
Name string
Usage string
EnvVar string
Destination * bool
Hide bool
}
// String returns a readable representation of this value (for usage defaults)
@ -293,6 +311,10 @@ func (f BoolFlag) GetName() string {
return f . Name
}
func ( f BoolFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// BoolTFlag this represents a boolean flag that is true by default, but can
// still be set to false by --some-flag=false
type BoolTFlag struct {
@ -300,6 +322,7 @@ type BoolTFlag struct {
Usage string
EnvVar string
Destination * bool
Hide bool
}
// String returns a readable representation of this value (for usage defaults)
@ -337,6 +360,10 @@ func (f BoolTFlag) GetName() string {
return f . Name
}
func ( f BoolTFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// StringFlag represents a flag that takes as string value
type StringFlag struct {
Name string
@ -344,6 +371,7 @@ type StringFlag struct {
Usage string
EnvVar string
Destination * string
Hide bool
}
// String returns the usage
@ -385,6 +413,10 @@ func (f StringFlag) GetName() string {
return f . Name
}
func ( f StringFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// IntFlag is a flag that takes an integer
// Errors if the value provided cannot be parsed
type IntFlag struct {
@ -393,6 +425,7 @@ type IntFlag struct {
Usage string
EnvVar string
Destination * int
Hide bool
}
// String returns the usage
@ -429,6 +462,10 @@ func (f IntFlag) GetName() string {
return f . Name
}
func ( f IntFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// DurationFlag is a flag that takes a duration specified in Go's duration
// format: https://golang.org/pkg/time/#ParseDuration
type DurationFlag struct {
@ -437,6 +474,7 @@ type DurationFlag struct {
Usage string
EnvVar string
Destination * time . Duration
Hide bool
}
// String returns a readable representation of this value (for usage defaults)
@ -473,6 +511,10 @@ func (f DurationFlag) GetName() string {
return f . Name
}
func ( f DurationFlag ) isNotHidden ( ) bool {
return ! f . Hide
}
// Float64Flag is a flag that takes an float value
// Errors if the value provided cannot be parsed
type Float64Flag struct {
@ -481,6 +523,7 @@ type Float64Flag struct {
Usage string
EnvVar string
Destination * float64
Hide bool
}
// String returns the usage
@ -516,6 +559,10 @@ func (f Float64Flag) GetName() string {
return f . Name
}
func ( f Float64Flag ) isNotHidden ( ) bool {
return ! f . Hide
}
func prefixFor ( name string ) ( prefix string ) {
if len ( name ) == 1 {
prefix = "-"