Skip to content

Commit

Permalink
fix: allow required flag with one character (#1449)
Browse files Browse the repository at this point in the history
* fix: allow required flag with one character

* fix: update test case
  • Loading branch information
Gerrard-YNWA committed Aug 29, 2022
1 parent 8b23e7b commit b98c059
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions context.go
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions context_test.go
Expand Up @@ -556,6 +556,14 @@ func TestCheckRequiredFlags(t *testing.T) {
&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 {
Expand Down

0 comments on commit b98c059

Please sign in to comment.