1
0

Update module spf13/cobra to v1 (#511)

Update module spf13/cobra to v1

Reviewed-on: https://kolaente.dev/vikunja/api/pulls/511
This commit is contained in:
renovate
2020-05-14 19:09:06 +00:00
committed by konrad
parent 91a3b7aba2
commit 4533ac6b28
11 changed files with 855 additions and 61 deletions

View File

@ -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]))
}
}