mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
command/ValidateArgs: check ValidArgs regardless of Args being nil
This commit is contained in:
parent
cf1c00d205
commit
cea5d74d57
1 changed files with 6 additions and 5 deletions
11
command.go
11
command.go
|
@ -995,15 +995,16 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
return cmd, err
|
return cmd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateArgs returns an error if any positional args are not in
|
// ValidateArgs returns an error if any positional args are not in the
|
||||||
// the `ValidArgs` field of `Command`
|
// `ValidArgs` field of `Command`. Then, run the `Args` validator, if
|
||||||
|
// specified.
|
||||||
func (c *Command) ValidateArgs(args []string) error {
|
func (c *Command) ValidateArgs(args []string) error {
|
||||||
if c.Args == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := validateArgs(c, args); err != nil {
|
if err := validateArgs(c, args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if c.Args == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return c.Args(c, args)
|
return c.Args(c, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue