diff --git a/context.go b/context.go index 6b497ed20d..3a78c267d8 100644 --- a/context.go +++ b/context.go @@ -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 diff --git a/context_test.go b/context_test.go index 84757063eb..55a9ead891 100644 --- a/context_test.go +++ b/context_test.go @@ -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 {