Skip to content

Commit

Permalink
Merge pull request #1126 from oleorhagen/reqflagerr
Browse files Browse the repository at this point in the history
fix: Print the long options of the required flags missing
  • Loading branch information
rliebz authored May 2, 2020
2 parents 053ba9d + ee2fae6 commit 1e44266
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr {
var flagPresent bool
var flagName string
for _, key := range strings.Split(f.GetName(), ",") {
key = strings.TrimSpace(key)
if len(key) > 1 {
flagName = key
}

if context.IsSet(strings.TrimSpace(key)) {
if context.IsSet(key) {
flagPresent = true
}
}
Expand Down
8 changes: 8 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ func TestCheckRequiredFlags(t *testing.T) {
},
parseInput: []string{"-n", "asd", "-n", "qwe"},
},
{
testCase: "required_flag_with_short_alias_not_printed_on_error",
expectedAnError: true,
expectedErrorContents: []string{"Required flag \"names\" not set"},
flags: []Flag{
StringSliceFlag{Name: "names, n", Required: true},
},
},
}
for _, test := range tdata {
t.Run(test.testCase, func(t *testing.T) {
Expand Down

0 comments on commit 1e44266

Please sign in to comment.