forked from TrueCloudLab/rclone
vendor: update version of github.com/spf13/cobra for zsh support
This commit is contained in:
parent
2c8d6e86cc
commit
7e93567b18
26 changed files with 683 additions and 278 deletions
56
vendor/github.com/spf13/cobra/command.go
generated
vendored
56
vendor/github.com/spf13/cobra/command.go
generated
vendored
|
@ -54,6 +54,9 @@ type Command struct {
|
|||
// ValidArgs is list of all valid non-flag arguments that are accepted in bash completions
|
||||
ValidArgs []string
|
||||
|
||||
// Expected arguments
|
||||
Args PositionalArgs
|
||||
|
||||
// ArgAliases is List of aliases for ValidArgs.
|
||||
// These are not suggested to the user in the bash completion,
|
||||
// but accepted if entered manually.
|
||||
|
@ -513,33 +516,29 @@ func (c *Command) Find(args []string) (*Command, []string, error) {
|
|||
}
|
||||
|
||||
commandFound, a := innerfind(c, args)
|
||||
argsWOflags := stripFlags(a, commandFound)
|
||||
|
||||
// no subcommand, always take args
|
||||
if !commandFound.HasSubCommands() {
|
||||
return commandFound, a, nil
|
||||
if commandFound.Args == nil {
|
||||
return commandFound, a, legacyArgs(commandFound, stripFlags(a, commandFound))
|
||||
}
|
||||
|
||||
// root command with subcommands, do subcommand checking
|
||||
if commandFound == c && len(argsWOflags) > 0 {
|
||||
suggestionsString := ""
|
||||
if !c.DisableSuggestions {
|
||||
if c.SuggestionsMinimumDistance <= 0 {
|
||||
c.SuggestionsMinimumDistance = 2
|
||||
}
|
||||
if suggestions := c.SuggestionsFor(argsWOflags[0]); len(suggestions) > 0 {
|
||||
suggestionsString += "\n\nDid you mean this?\n"
|
||||
for _, s := range suggestions {
|
||||
suggestionsString += fmt.Sprintf("\t%v\n", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return commandFound, a, fmt.Errorf("unknown command %q for %q%s", argsWOflags[0], commandFound.CommandPath(), suggestionsString)
|
||||
}
|
||||
|
||||
return commandFound, a, nil
|
||||
}
|
||||
|
||||
func (c *Command) findSuggestions(arg string) string {
|
||||
if c.DisableSuggestions {
|
||||
return ""
|
||||
}
|
||||
if c.SuggestionsMinimumDistance <= 0 {
|
||||
c.SuggestionsMinimumDistance = 2
|
||||
}
|
||||
suggestionsString := ""
|
||||
if suggestions := c.SuggestionsFor(arg); len(suggestions) > 0 {
|
||||
suggestionsString += "\n\nDid you mean this?\n"
|
||||
for _, s := range suggestions {
|
||||
suggestionsString += fmt.Sprintf("\t%v\n", s)
|
||||
}
|
||||
}
|
||||
return suggestionsString
|
||||
}
|
||||
|
||||
// SuggestionsFor provides suggestions for the typedName.
|
||||
func (c *Command) SuggestionsFor(typedName string) []string {
|
||||
suggestions := []string{}
|
||||
|
@ -624,6 +623,10 @@ func (c *Command) execute(a []string) (err error) {
|
|||
argWoFlags = a
|
||||
}
|
||||
|
||||
if err := c.ValidateArgs(argWoFlags); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for p := c; p != nil; p = p.Parent() {
|
||||
if p.PersistentPreRunE != nil {
|
||||
if err := p.PersistentPreRunE(c, argWoFlags); err != nil {
|
||||
|
@ -747,6 +750,13 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
|||
return cmd, err
|
||||
}
|
||||
|
||||
func (c *Command) ValidateArgs(args []string) error {
|
||||
if c.Args == nil {
|
||||
return nil
|
||||
}
|
||||
return c.Args(c, args)
|
||||
}
|
||||
|
||||
// InitDefaultHelpFlag adds default help flag to c.
|
||||
// It is called automatically by executing the c or by calling help and usage.
|
||||
// If c already has help flag, it will do nothing.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue