Fix some issues with cli related to argument values

This commit is contained in:
Sasha Koshka 2024-02-11 12:37:08 -05:00
parent 385657a5c1
commit 928bf64d9d

View File

@ -60,7 +60,14 @@ func (this *Cli) Parse (args []string) error {
flag.String() +
" requires a value")
}
flag.Value = next()
value := next()
err := flag.Validate(value)
if err != nil {
return errors.New(fmt.Sprint (
"could not parse ", flag.String(), ": ",
err))
}
flag.Value = value
}
return nil
}
@ -207,7 +214,7 @@ func NewFlag (short rune, long string, help string) *Flag {
// NewInputFlag creates a new flag that does take in a value. This function will
// panic if the given validation function is nil.
func NewInputFlag (short rune, long string, help string, defaul string, validate func (string) error) *Flag {
if validate != nil {
if validate == nil {
panic("validate must be non-nil for a flag to take in a value")
}
return &Flag {