diff --git a/context.go b/context.go index 216e958..e79ec34 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 8475706..5cef65e 100644 --- a/context_test.go +++ b/context_test.go @@ -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 {