fix: allow required flag with one character (#1449)
* fix: allow required flag with one character * fix: update test case
This commit is contained in:
parent
8b23e7b1e9
commit
b98c059269
@ -170,9 +170,7 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr {
|
|||||||
var flagName string
|
var flagName string
|
||||||
|
|
||||||
for _, key := range f.Names() {
|
for _, key := range f.Names() {
|
||||||
if len(key) > 1 {
|
flagName = key
|
||||||
flagName = key
|
|
||||||
}
|
|
||||||
|
|
||||||
if cCtx.IsSet(strings.TrimSpace(key)) {
|
if cCtx.IsSet(strings.TrimSpace(key)) {
|
||||||
flagPresent = true
|
flagPresent = true
|
||||||
|
@ -556,6 +556,14 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
&StringSliceFlag{Name: "names, n", Required: true},
|
&StringSliceFlag{Name: "names, n", Required: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testCase: "required_flag_with_one_character",
|
||||||
|
expectedAnError: true,
|
||||||
|
expectedErrorContents: []string{"Required flag \"n\" not set"},
|
||||||
|
flags: []Flag{
|
||||||
|
&StringFlag{Name: "n", Required: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tdata {
|
for _, test := range tdata {
|
||||||
|
Loading…
Reference in New Issue
Block a user