Skip to content

Commit

Permalink
Improved error message for missing required flags: now list all missi…
Browse files Browse the repository at this point in the history
…ng required flags for better user guidance. (#340)

Issue: #215
  • Loading branch information
arun-gajaraj committed Sep 30, 2023
1 parent 4702584 commit 64d23c5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,18 @@ func (a *Application) validateRequired(context *ParseContext) error {
}

// Check required flags and set defaults.
var missingFlags []string
for _, flag := range context.flags.long {
if flagElements[flag.name] == nil {
// Check required flags were provided.
if flag.needsValue() {
return fmt.Errorf("required flag --%s not provided", flag.name)
missingFlags = append(missingFlags, fmt.Sprintf("'--%s'", flag.name))
}
}
}
if len(missingFlags) != 0 {
return fmt.Errorf("required flag(s) %s not provided", strings.Join(missingFlags, ", "))
}

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

0 comments on commit 64d23c5

Please sign in to comment.