Skip to content

Commit 1e44266

Browse files
authored
Merge pull request #1126 from oleorhagen/reqflagerr
fix: Print the long options of the required flags missing
2 parents 053ba9d + ee2fae6 commit 1e44266

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr {
324324
var flagPresent bool
325325
var flagName string
326326
for _, key := range strings.Split(f.GetName(), ",") {
327+
key = strings.TrimSpace(key)
327328
if len(key) > 1 {
328329
flagName = key
329330
}
330331

331-
if context.IsSet(strings.TrimSpace(key)) {
332+
if context.IsSet(key) {
332333
flagPresent = true
333334
}
334335
}

context_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,14 @@ func TestCheckRequiredFlags(t *testing.T) {
576576
},
577577
parseInput: []string{"-n", "asd", "-n", "qwe"},
578578
},
579+
{
580+
testCase: "required_flag_with_short_alias_not_printed_on_error",
581+
expectedAnError: true,
582+
expectedErrorContents: []string{"Required flag \"names\" not set"},
583+
flags: []Flag{
584+
StringSliceFlag{Name: "names, n", Required: true},
585+
},
586+
},
579587
}
580588
for _, test := range tdata {
581589
t.Run(test.testCase, func(t *testing.T) {

0 commit comments

Comments
 (0)