summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/cobra/args.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/cobra/args.go')
-rw-r--r--vendor/github.com/spf13/cobra/args.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/vendor/github.com/spf13/cobra/args.go b/vendor/github.com/spf13/cobra/args.go
index c4d820b85..70e9b2629 100644
--- a/vendor/github.com/spf13/cobra/args.go
+++ b/vendor/github.com/spf13/cobra/args.go
@@ -2,6 +2,7 @@ package cobra
import (
"fmt"
+ "strings"
)
type PositionalArgs func(cmd *Command, args []string) error
@@ -34,8 +35,15 @@ func NoArgs(cmd *Command, args []string) error {
// OnlyValidArgs returns an error if any args are not in the list of ValidArgs.
func OnlyValidArgs(cmd *Command, args []string) error {
if len(cmd.ValidArgs) > 0 {
+ // Remove any description that may be included in ValidArgs.
+ // A description is following a tab character.
+ var validArgs []string
+ for _, v := range cmd.ValidArgs {
+ validArgs = append(validArgs, strings.Split(v, "\t")[0])
+ }
+
for _, v := range args {
- if !stringInSlice(v, cmd.ValidArgs) {
+ if !stringInSlice(v, validArgs) {
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
}
}