Skip to content

Commit 64d23c5

Browse files
authored
Improved error message for missing required flags: now list all missing required flags for better user guidance. (#340)
Issue: #215
1 parent 4702584 commit 64d23c5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,18 @@ func (a *Application) validateRequired(context *ParseContext) error {
464464
}
465465

466466
// Check required flags and set defaults.
467+
var missingFlags []string
467468
for _, flag := range context.flags.long {
468469
if flagElements[flag.name] == nil {
469470
// Check required flags were provided.
470471
if flag.needsValue() {
471-
return fmt.Errorf("required flag --%s not provided", flag.name)
472+
missingFlags = append(missingFlags, fmt.Sprintf("'--%s'", flag.name))
472473
}
473474
}
474475
}
476+
if len(missingFlags) != 0 {
477+
return fmt.Errorf("required flag(s) %s not provided", strings.Join(missingFlags, ", "))
478+
}
475479

476480
for _, arg := range context.arguments.args {
477481
if argElements[arg.name] == nil {

0 commit comments

Comments
 (0)