fix: allow required flag with one character

This commit is contained in:
gerrard 2022-08-14 19:06:34 +08:00 committed by Dan Buch
parent 382386a079
commit 9de6fa4ded
Signed by: meatballhat
GPG Key ID: A12F782281063434
2 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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 {