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