forked from TrueCloudLab/rclone
vendor: update github.com/spf13/cobra to v1.0.0
This commit is contained in:
parent
f37af9afec
commit
3b4c24af4e
14 changed files with 914 additions and 89 deletions
10
vendor/github.com/spf13/cobra/args.go
generated
vendored
10
vendor/github.com/spf13/cobra/args.go
generated
vendored
|
@ -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]))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue