Merge remote-tracking branch 'origin/v1' into merging-from-v1
This commit is contained in:
281
flag.go
281
flag.go
@@ -77,23 +77,6 @@ type Generic interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// GenericFlag is the flag type for types implementing Generic
|
||||
type GenericFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value Generic
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the string representation of the generic flag to display the
|
||||
// help text to the user (uses the String() method of the generic flag to show
|
||||
// the value)
|
||||
func (f *GenericFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply takes the flagset and calls Set on the generic flag with the value
|
||||
// provided by the user for parsing by the flag
|
||||
func (f *GenericFlag) Apply(set *flag.FlagSet) {
|
||||
@@ -112,11 +95,6 @@ func (f *GenericFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of a flag.
|
||||
func (f *GenericFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// StringSlice wraps a []string to satisfy flag.Value
|
||||
type StringSlice struct {
|
||||
slice []string
|
||||
@@ -162,22 +140,6 @@ func (f *StringSlice) Value() []string {
|
||||
return f.slice
|
||||
}
|
||||
|
||||
// StringSliceFlag is a string flag that can be specified multiple times on the
|
||||
// command-line
|
||||
type StringSliceFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value *StringSlice
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *StringSliceFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *StringSliceFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -203,11 +165,6 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of a flag.
|
||||
func (f *StringSliceFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// IntSlice wraps an []int to satisfy flag.Value
|
||||
type IntSlice struct {
|
||||
slice []int
|
||||
@@ -273,22 +230,6 @@ func (i *IntSlice) Value() []int {
|
||||
return i.slice
|
||||
}
|
||||
|
||||
// IntSliceFlag is an int flag that can be specified multiple times on the
|
||||
// command-line
|
||||
type IntSliceFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value *IntSlice
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *IntSliceFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -317,11 +258,6 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *IntSliceFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// Int64Slice is an opaque type for []int to satisfy flag.Value
|
||||
type Int64Slice struct {
|
||||
slice []int64
|
||||
@@ -367,22 +303,6 @@ func (f *Int64Slice) Value() []int64 {
|
||||
return f.slice
|
||||
}
|
||||
|
||||
// Int64SliceFlag is an int flag that can be specified multiple times on the
|
||||
// command-line
|
||||
type Int64SliceFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value *Int64Slice
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *Int64SliceFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *Int64SliceFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -411,27 +331,6 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of the flag.
|
||||
func (f *Int64SliceFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// BoolFlag is a switch that defaults to false
|
||||
type BoolFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value bool
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *bool
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns a readable representation of this value (for usage defaults)
|
||||
func (f *BoolFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *BoolFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -455,27 +354,6 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *BoolFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// StringFlag represents a flag that takes as string value
|
||||
type StringFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value string
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *StringFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *StringFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -496,27 +374,6 @@ func (f *StringFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *StringFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// IntFlag is a flag that takes an integer
|
||||
type IntFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value int
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *int
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *IntFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *IntFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -540,27 +397,6 @@ func (f *IntFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *IntFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// Int64Flag is a flag that takes a 64-bit integer
|
||||
type Int64Flag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value int64
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *int64
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *Int64Flag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *Int64Flag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -584,27 +420,6 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of the flag.
|
||||
func (f *Int64Flag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// UintFlag is a flag that takes an unsigned integer
|
||||
type UintFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value uint
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *uint
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *UintFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *UintFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -628,27 +443,6 @@ func (f *UintFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of the flag.
|
||||
func (f *UintFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// Uint64Flag is a flag that takes an unsigned 64-bit integer
|
||||
type Uint64Flag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value uint64
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *uint64
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *Uint64Flag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *Uint64Flag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -672,28 +466,6 @@ func (f *Uint64Flag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of the flag.
|
||||
func (f *Uint64Flag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// DurationFlag is a flag that takes a duration specified in Go's duration
|
||||
// format: https://golang.org/pkg/time/#ParseDuration
|
||||
type DurationFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value time.Duration
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *time.Duration
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns a readable representation of this value (for usage defaults)
|
||||
func (f *DurationFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *DurationFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -717,27 +489,6 @@ func (f *DurationFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *DurationFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
// Float64Flag is a flag that takes an float value
|
||||
type Float64Flag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value float64
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Destination *float64
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *Float64Flag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *Float64Flag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -760,20 +511,11 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the name of the flag.
|
||||
func (f *Float64Flag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// NewFloat64Slice makes a *Float64Slice with default values
|
||||
func NewFloat64Slice(defaults ...float64) *Float64Slice {
|
||||
return &Float64Slice{slice: append([]float64{}, defaults...)}
|
||||
}
|
||||
|
||||
|
||||
// Float64Slice is an opaque type for []float64 to satisfy flag.Value
|
||||
type Float64Slice struct {
|
||||
slice []float64
|
||||
@@ -819,22 +561,6 @@ func (f *Float64Slice) Value() []float64 {
|
||||
return f.slice
|
||||
}
|
||||
|
||||
// Float64SliceFlag is a float64 flag that can be specified multiple times on the
|
||||
// command-line
|
||||
type Float64SliceFlag struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Value *Float64Slice
|
||||
Usage string
|
||||
EnvVars []string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// String returns the usage
|
||||
func (f *Float64SliceFlag) String() string {
|
||||
return FlagStringer(f)
|
||||
}
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *Float64SliceFlag) Apply(set *flag.FlagSet) {
|
||||
if f.EnvVars != nil {
|
||||
@@ -863,13 +589,6 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// Names returns the names of the flag.
|
||||
func (f *Float64SliceFlag) Names() []string {
|
||||
return flagNames(f)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func visibleFlags(fl []Flag) []Flag {
|
||||
visible := []Flag{}
|
||||
for _, flag := range fl {
|
||||
|
Reference in New Issue
Block a user