Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Print the long options of the required flags missing #1126

Merged
merged 2 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"},
rliebz marked this conversation as resolved.
Show resolved Hide resolved
flags: []Flag{
StringSliceFlag{Name: "names, n", Required: true},
},
},
}
for _, test := range tdata {
t.Run(test.testCase, func(t *testing.T) {
Expand Down