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