Skip to content

Commit

Permalink
Prefix validation error with argument name
Browse files Browse the repository at this point in the history
Currently, it is not possible for a custom validation function to know the name
of the argument. This prefixes it with the argument name like the built-in
functions.
  • Loading branch information
look committed Jul 29, 2022
1 parent 65ad70c commit f8e9eea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ func (o *arg) parse(args []string, argCount int) error {
return fmt.Errorf("[%s] can only be present once", o.name())
}

// If validation function provided -- execute, on error return it immediately
// If validation function provided -- execute, on error return immediately
if o.opts != nil && o.opts.Validate != nil {
err := o.opts.Validate(args)
if err != nil {
return err
return fmt.Errorf("[%s] %w", o.name(), err)
}
}
return o.parseSomeType(args, argCount)
Expand Down

0 comments on commit f8e9eea

Please sign in to comment.