mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: github.com/spf13/cobra v1.1.1
v1.1.1: - Fix: yaml.v2 2.3.0 contained a unintended breaking change. This release reverts to yaml.v2 v2.2.8 which has recent critical CVE fixes, but does not have the breaking changes. - Fix: correct internal formatting for go-md2man v2 (which caused man page generation to be broken). v1.1.0: - Extend Go completions and revamp zsh comp - Add completion for help command - Complete subcommands when TraverseChildren is set - Fix stderr printing functions - fix: fish output redirection Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
46
vendor/github.com/spf13/cobra/command.go
generated
vendored
46
vendor/github.com/spf13/cobra/command.go
generated
vendored
@ -37,6 +37,14 @@ type FParseErrWhitelist flag.ParseErrorsWhitelist
|
||||
// definition to ensure usability.
|
||||
type Command struct {
|
||||
// Use is the one-line usage message.
|
||||
// Recommended syntax is as follow:
|
||||
// [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required.
|
||||
// ... indicates that you can specify multiple values for the previous argument.
|
||||
// | indicates mutually exclusive information. You can use the argument to the left of the separator or the
|
||||
// argument to the right of the separator. You cannot use both arguments in a single use of the command.
|
||||
// { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are
|
||||
// optional, they are enclosed in brackets ([ ]).
|
||||
// Example: add [-F file | -D dir]... [-f format] profile
|
||||
Use string
|
||||
|
||||
// Aliases is an array of aliases that can be used instead of the first word in Use.
|
||||
@ -359,7 +367,7 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
|
||||
c.mergePersistentFlags()
|
||||
err := tmpl(c.OutOrStderr(), c.UsageTemplate(), c)
|
||||
if err != nil {
|
||||
c.Println(err)
|
||||
c.PrintErrln(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -387,7 +395,7 @@ func (c *Command) HelpFunc() func(*Command, []string) {
|
||||
// See https://github.com/spf13/cobra/issues/1002
|
||||
err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
|
||||
if err != nil {
|
||||
c.Println(err)
|
||||
c.PrintErrln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -930,8 +938,8 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||
c = cmd
|
||||
}
|
||||
if !c.SilenceErrors {
|
||||
c.Println("Error:", err.Error())
|
||||
c.Printf("Run '%v --help' for usage.\n", c.CommandPath())
|
||||
c.PrintErrln("Error:", err.Error())
|
||||
c.PrintErrf("Run '%v --help' for usage.\n", c.CommandPath())
|
||||
}
|
||||
return c, err
|
||||
}
|
||||
@ -959,7 +967,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||
// If root command has SilentErrors flagged,
|
||||
// all subcommands should respect it
|
||||
if !cmd.SilenceErrors && !c.SilenceErrors {
|
||||
c.Println("Error:", err.Error())
|
||||
c.PrintErrln("Error:", err.Error())
|
||||
}
|
||||
|
||||
// If root command has SilentUsage flagged,
|
||||
@ -979,6 +987,10 @@ func (c *Command) ValidateArgs(args []string) error {
|
||||
}
|
||||
|
||||
func (c *Command) validateRequiredFlags() error {
|
||||
if c.DisableFlagParsing {
|
||||
return nil
|
||||
}
|
||||
|
||||
flags := c.Flags()
|
||||
missingFlagNames := []string{}
|
||||
flags.VisitAll(func(pflag *flag.Flag) {
|
||||
@ -1052,7 +1064,25 @@ func (c *Command) InitDefaultHelpCmd() {
|
||||
Short: "Help about any command",
|
||||
Long: `Help provides help for any command in the application.
|
||||
Simply type ` + c.Name() + ` help [path to command] for full details.`,
|
||||
|
||||
ValidArgsFunction: func(c *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||
var completions []string
|
||||
cmd, _, e := c.Root().Find(args)
|
||||
if e != nil {
|
||||
return nil, ShellCompDirectiveNoFileComp
|
||||
}
|
||||
if cmd == nil {
|
||||
// Root help command.
|
||||
cmd = c.Root()
|
||||
}
|
||||
for _, subCmd := range cmd.Commands() {
|
||||
if subCmd.IsAvailableCommand() || subCmd == cmd.helpCommand {
|
||||
if strings.HasPrefix(subCmd.Name(), toComplete) {
|
||||
completions = append(completions, fmt.Sprintf("%s\t%s", subCmd.Name(), subCmd.Short))
|
||||
}
|
||||
}
|
||||
}
|
||||
return completions, ShellCompDirectiveNoFileComp
|
||||
},
|
||||
Run: func(c *Command, args []string) {
|
||||
cmd, _, e := c.Root().Find(args)
|
||||
if cmd == nil || e != nil {
|
||||
@ -1179,12 +1209,12 @@ func (c *Command) PrintErr(i ...interface{}) {
|
||||
|
||||
// PrintErrln is a convenience method to Println to the defined Err output, fallback to Stderr if not set.
|
||||
func (c *Command) PrintErrln(i ...interface{}) {
|
||||
c.Print(fmt.Sprintln(i...))
|
||||
c.PrintErr(fmt.Sprintln(i...))
|
||||
}
|
||||
|
||||
// PrintErrf is a convenience method to Printf to the defined Err output, fallback to Stderr if not set.
|
||||
func (c *Command) PrintErrf(format string, i ...interface{}) {
|
||||
c.Print(fmt.Sprintf(format, i...))
|
||||
c.PrintErr(fmt.Sprintf(format, i...))
|
||||
}
|
||||
|
||||
// CommandPath returns the full path to this command.
|
||||
|
Reference in New Issue
Block a user