From f8e9eea1ff06aecb5e450b18a6b9aaa1b25e8295 Mon Sep 17 00:00:00 2001 From: Luke Francl Date: Fri, 29 Jul 2022 11:19:35 -0700 Subject: [PATCH] Prefix validation error with argument name 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. --- argument.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/argument.go b/argument.go index 0fca9d5..f6a2631 100644 --- a/argument.go +++ b/argument.go @@ -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)