Skip to content

Commit b98c059

Browse files
authored
fix: allow required flag with one character (#1449)
* fix: allow required flag with one character * fix: update test case
1 parent 8b23e7b commit b98c059

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

context.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr {
170170
var flagName string
171171

172172
for _, key := range f.Names() {
173-
if len(key) > 1 {
174-
flagName = key
175-
}
173+
flagName = key
176174

177175
if cCtx.IsSet(strings.TrimSpace(key)) {
178176
flagPresent = true

context_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,14 @@ func TestCheckRequiredFlags(t *testing.T) {
556556
&StringSliceFlag{Name: "names, n", Required: true},
557557
},
558558
},
559+
{
560+
testCase: "required_flag_with_one_character",
561+
expectedAnError: true,
562+
expectedErrorContents: []string{"Required flag \"n\" not set"},
563+
flags: []Flag{
564+
&StringFlag{Name: "n", Required: true},
565+
},
566+
},
559567
}
560568

561569
for _, test := range tdata {

0 commit comments

Comments
 (0)