Fix tests per latest main
This commit is contained in:
parent
0764ca2295
commit
7097d0eedd
16
flag_test.go
16
flag_test.go
@ -1201,10 +1201,10 @@ var uintSliceFlagTests = []struct {
|
||||
value *UintSlice
|
||||
expected string
|
||||
}{
|
||||
{"heads", nil, NewUintSlice(), "--heads value\t(accepts multiple inputs)"},
|
||||
{"H", nil, NewUintSlice(), "-H value\t(accepts multiple inputs)"},
|
||||
{"heads", nil, NewUintSlice(), "--heads value [ --heads value ]\t"},
|
||||
{"H", nil, NewUintSlice(), "-H value [ -H value ]\t"},
|
||||
{"heads", []string{"H"}, NewUintSlice(uint(2), uint(17179869184)),
|
||||
"--heads value, -H value\t(default: 2, 17179869184)\t(accepts multiple inputs)"},
|
||||
"--heads value, -H value [ --heads value, -H value ]\t(default: 2, 17179869184)"},
|
||||
}
|
||||
|
||||
func TestUintSliceFlagHelpOutput(t *testing.T) {
|
||||
@ -1297,10 +1297,10 @@ var uint64SliceFlagTests = []struct {
|
||||
value *Uint64Slice
|
||||
expected string
|
||||
}{
|
||||
{"heads", nil, NewUint64Slice(), "--heads value\t(accepts multiple inputs)"},
|
||||
{"H", nil, NewUint64Slice(), "-H value\t(accepts multiple inputs)"},
|
||||
{"heads", nil, NewUint64Slice(), "--heads value [ --heads value ]\t"},
|
||||
{"H", nil, NewUint64Slice(), "-H value [ -H value ]\t"},
|
||||
{"heads", []string{"H"}, NewUint64Slice(uint64(2), uint64(17179869184)),
|
||||
"--heads value, -H value\t(default: 2, 17179869184)\t(accepts multiple inputs)"},
|
||||
"--heads value, -H value [ --heads value, -H value ]\t(default: 2, 17179869184)"},
|
||||
}
|
||||
|
||||
func TestUint64SliceFlagHelpOutput(t *testing.T) {
|
||||
@ -2703,13 +2703,13 @@ func TestFlagDefaultValue(t *testing.T) {
|
||||
name: "uint64Slice",
|
||||
flag: &Uint64SliceFlag{Name: "flag", Value: NewUint64Slice(1, 2)},
|
||||
toParse: []string{"--flag", "13"},
|
||||
expect: `--flag value (default: 1, 2) (accepts multiple inputs)`,
|
||||
expect: `--flag value [ --flag value ] (default: 1, 2)`,
|
||||
},
|
||||
{
|
||||
name: "uintSlice",
|
||||
flag: &UintSliceFlag{Name: "flag", Value: NewUintSlice(1, 2)},
|
||||
toParse: []string{"--flag", "13"},
|
||||
expect: `--flag value (default: 1, 2) (accepts multiple inputs)`,
|
||||
expect: `--flag value [ --flag value ] (default: 1, 2)`,
|
||||
},
|
||||
{
|
||||
name: "string",
|
||||
|
@ -88,7 +88,7 @@ func (i *Uint64Slice) Get() interface{} {
|
||||
// String returns a readable representation of this value
|
||||
// (for usage defaults)
|
||||
func (f *Uint64SliceFlag) String() string {
|
||||
return withEnvHint(f.GetEnvVars(), stringifyUint64SliceFlag(f))
|
||||
return withEnvHint(f.GetEnvVars(), f.stringify())
|
||||
}
|
||||
|
||||
// TakesValue returns true of the flag takes a value, otherwise false
|
||||
@ -172,6 +172,17 @@ func (f *Uint64SliceFlag) Get(ctx *Context) []uint64 {
|
||||
return ctx.Uint64Slice(f.Name)
|
||||
}
|
||||
|
||||
func (f *Uint64SliceFlag) stringify() string {
|
||||
var defaultVals []string
|
||||
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||
for _, i := range f.Value.Value() {
|
||||
defaultVals = append(defaultVals, strconv.FormatUint(i, 10))
|
||||
}
|
||||
}
|
||||
|
||||
return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
|
||||
}
|
||||
|
||||
// Uint64Slice looks up the value of a local Uint64SliceFlag, returns
|
||||
// nil if not found
|
||||
func (cCtx *Context) Uint64Slice(name string) []uint64 {
|
||||
|
@ -99,7 +99,7 @@ func (i *UintSlice) Get() interface{} {
|
||||
// String returns a readable representation of this value
|
||||
// (for usage defaults)
|
||||
func (f *UintSliceFlag) String() string {
|
||||
return withEnvHint(f.GetEnvVars(), stringifyUintSliceFlag(f))
|
||||
return withEnvHint(f.GetEnvVars(), f.stringify())
|
||||
}
|
||||
|
||||
// TakesValue returns true of the flag takes a value, otherwise false
|
||||
@ -183,6 +183,17 @@ func (f *UintSliceFlag) Get(ctx *Context) []uint {
|
||||
return ctx.UintSlice(f.Name)
|
||||
}
|
||||
|
||||
func (f *UintSliceFlag) stringify() string {
|
||||
var defaultVals []string
|
||||
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||
for _, i := range f.Value.Value() {
|
||||
defaultVals = append(defaultVals, strconv.FormatUint(uint64(i), 10))
|
||||
}
|
||||
}
|
||||
|
||||
return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
|
||||
}
|
||||
|
||||
// UintSlice looks up the value of a local UintSliceFlag, returns
|
||||
// nil if not found
|
||||
func (cCtx *Context) UintSlice(name string) []uint {
|
||||
|
Loading…
Reference in New Issue
Block a user