|
|
@ -189,7 +189,7 @@ func (f *IntSlice) Set(value string) error {
|
|
|
|
|
|
|
|
|
|
|
|
// String returns a readable representation of this value (for usage defaults)
|
|
|
|
// String returns a readable representation of this value (for usage defaults)
|
|
|
|
func (f *IntSlice) String() string {
|
|
|
|
func (f *IntSlice) String() string {
|
|
|
|
return fmt.Sprintf("%d", *f)
|
|
|
|
return fmt.Sprintf("%#v", *f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Value returns the slice of ints set by this flag
|
|
|
|
// Value returns the slice of ints set by this flag
|
|
|
@ -245,6 +245,77 @@ func (f IntSliceFlag) GetName() string {
|
|
|
|
return f.Name
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Int64Slice is an opaque type for []int to satisfy flag.Value
|
|
|
|
|
|
|
|
type Int64Slice []int64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set parses the value into an integer and appends it to the list of values
|
|
|
|
|
|
|
|
func (f *Int64Slice) Set(value string) error {
|
|
|
|
|
|
|
|
tmp, err := strconv.ParseInt(value, 10, 64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*f = append(*f, tmp)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// String returns a readable representation of this value (for usage defaults)
|
|
|
|
|
|
|
|
func (f *Int64Slice) String() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("%#v", *f)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Value returns the slice of ints set by this flag
|
|
|
|
|
|
|
|
func (f *Int64Slice) Value() []int64 {
|
|
|
|
|
|
|
|
return *f
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Int64SliceFlag is an int flag that can be specified multiple times on the
|
|
|
|
|
|
|
|
// command-line
|
|
|
|
|
|
|
|
type Int64SliceFlag struct {
|
|
|
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
Value *Int64Slice
|
|
|
|
|
|
|
|
Usage string
|
|
|
|
|
|
|
|
EnvVar 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.EnvVar != "" {
|
|
|
|
|
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
|
|
|
|
newVal := &Int64Slice{}
|
|
|
|
|
|
|
|
for _, s := range strings.Split(envVal, ",") {
|
|
|
|
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
|
|
|
|
err := newVal.Set(s)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Fprintf(ErrWriter, err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f.Value = newVal
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eachName(f.Name, func(name string) {
|
|
|
|
|
|
|
|
if f.Value == nil {
|
|
|
|
|
|
|
|
f.Value = &Int64Slice{}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set.Var(f.Value, name, f.Usage)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetName returns the name of the flag.
|
|
|
|
|
|
|
|
func (f Int64SliceFlag) GetName() string {
|
|
|
|
|
|
|
|
return f.Name
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// BoolFlag is a switch that defaults to false
|
|
|
|
// BoolFlag is a switch that defaults to false
|
|
|
|
type BoolFlag struct {
|
|
|
|
type BoolFlag struct {
|
|
|
|
Name string
|
|
|
|
Name string
|
|
|
@ -376,7 +447,6 @@ func (f StringFlag) GetName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IntFlag is a flag that takes an integer
|
|
|
|
// IntFlag is a flag that takes an integer
|
|
|
|
// Errors if the value provided cannot be parsed
|
|
|
|
|
|
|
|
type IntFlag struct {
|
|
|
|
type IntFlag struct {
|
|
|
|
Name string
|
|
|
|
Name string
|
|
|
|
Value int
|
|
|
|
Value int
|
|
|
@ -420,6 +490,50 @@ func (f IntFlag) GetName() string {
|
|
|
|
return f.Name
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Int64Flag is a flag that takes a 64-bit integer
|
|
|
|
|
|
|
|
type Int64Flag struct {
|
|
|
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
Value int64
|
|
|
|
|
|
|
|
Usage string
|
|
|
|
|
|
|
|
EnvVar 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.EnvVar != "" {
|
|
|
|
|
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
|
|
|
|
envValInt, err := strconv.ParseInt(envVal, 0, 64)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
f.Value = envValInt
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eachName(f.Name, func(name string) {
|
|
|
|
|
|
|
|
if f.Destination != nil {
|
|
|
|
|
|
|
|
set.Int64Var(f.Destination, name, f.Value, f.Usage)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set.Int64(name, f.Value, f.Usage)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetName returns the name of the flag.
|
|
|
|
|
|
|
|
func (f Int64Flag) GetName() string {
|
|
|
|
|
|
|
|
return f.Name
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DurationFlag is a flag that takes a duration specified in Go's duration
|
|
|
|
// DurationFlag is a flag that takes a duration specified in Go's duration
|
|
|
|
// format: https://golang.org/pkg/time/#ParseDuration
|
|
|
|
// format: https://golang.org/pkg/time/#ParseDuration
|
|
|
|
type DurationFlag struct {
|
|
|
|
type DurationFlag struct {
|
|
|
@ -466,7 +580,6 @@ func (f DurationFlag) GetName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Float64Flag is a flag that takes an float value
|
|
|
|
// Float64Flag is a flag that takes an float value
|
|
|
|
// Errors if the value provided cannot be parsed
|
|
|
|
|
|
|
|
type Float64Flag struct {
|
|
|
|
type Float64Flag struct {
|
|
|
|
Name string
|
|
|
|
Name string
|
|
|
|
Value float64
|
|
|
|
Value float64
|
|
|
@ -593,6 +706,9 @@ func stringifyFlag(f Flag) string {
|
|
|
|
case IntSliceFlag:
|
|
|
|
case IntSliceFlag:
|
|
|
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
|
|
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
|
|
|
stringifyIntSliceFlag(f.(IntSliceFlag)))
|
|
|
|
stringifyIntSliceFlag(f.(IntSliceFlag)))
|
|
|
|
|
|
|
|
case Int64SliceFlag:
|
|
|
|
|
|
|
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
|
|
|
|
|
|
|
stringifyInt64SliceFlag(f.(Int64SliceFlag)))
|
|
|
|
case StringSliceFlag:
|
|
|
|
case StringSliceFlag:
|
|
|
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
|
|
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
|
|
|
stringifyStringSliceFlag(f.(StringSliceFlag)))
|
|
|
|
stringifyStringSliceFlag(f.(StringSliceFlag)))
|
|
|
@ -638,6 +754,17 @@ func stringifyIntSliceFlag(f IntSliceFlag) string {
|
|
|
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
|
|
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func stringifyInt64SliceFlag(f Int64SliceFlag) string {
|
|
|
|
|
|
|
|
defaultVals := []string{}
|
|
|
|
|
|
|
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
|
|
|
|
|
|
|
for _, i := range f.Value.Value() {
|
|
|
|
|
|
|
|
defaultVals = append(defaultVals, fmt.Sprintf("%d", i))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func stringifyStringSliceFlag(f StringSliceFlag) string {
|
|
|
|
func stringifyStringSliceFlag(f StringSliceFlag) string {
|
|
|
|
defaultVals := []string{}
|
|
|
|
defaultVals := []string{}
|
|
|
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
|
|
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
|
|
|