mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
update github.com/spf13/cobra for new flag options
This commit is contained in:
parent
4c87805870
commit
4ab4803b6b
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -231,7 +231,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/spf13/cobra",
|
"ImportPath": "github.com/spf13/cobra",
|
||||||
"Rev": "07a9dc0024fcc97a0dcb3117bdf8933367037f4e"
|
"Rev": "f8e1ec56bdd7494d309c69681267859a6bfb7549"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/spf13/pflag",
|
"ImportPath": "github.com/spf13/pflag",
|
||||||
|
8
Godeps/_workspace/src/github.com/spf13/cobra/cobra_test.go
generated
vendored
8
Godeps/_workspace/src/github.com/spf13/cobra/cobra_test.go
generated
vendored
@ -467,8 +467,16 @@ func TestRootHelp(t *testing.T) {
|
|||||||
t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)
|
t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(x.Output, cmdEcho.Use) {
|
||||||
|
t.Errorf("--help shouldn't display subcommand's usage, Got: \n %s", x.Output)
|
||||||
|
}
|
||||||
|
|
||||||
x = fullSetupTest("echo --help")
|
x = fullSetupTest("echo --help")
|
||||||
|
|
||||||
|
if strings.Contains(x.Output, cmdTimes.Use) {
|
||||||
|
t.Errorf("--help shouldn't display subsubcommand's usage, Got: \n %s", x.Output)
|
||||||
|
}
|
||||||
|
|
||||||
checkResultContains(t, x, "Available Commands:")
|
checkResultContains(t, x, "Available Commands:")
|
||||||
checkResultContains(t, x, "for more information about a command")
|
checkResultContains(t, x, "for more information about a command")
|
||||||
|
|
||||||
|
74
Godeps/_workspace/src/github.com/spf13/cobra/command.go
generated
vendored
74
Godeps/_workspace/src/github.com/spf13/cobra/command.go
generated
vendored
@ -40,6 +40,8 @@ type Command struct {
|
|||||||
Short string
|
Short string
|
||||||
// The long message shown in the 'help <this-command>' output.
|
// The long message shown in the 'help <this-command>' output.
|
||||||
Long string
|
Long string
|
||||||
|
// Examples of how to use the command
|
||||||
|
Example string
|
||||||
// Full set of flags
|
// Full set of flags
|
||||||
flags *flag.FlagSet
|
flags *flag.FlagSet
|
||||||
// Set of flags childrens of this command will inherit
|
// Set of flags childrens of this command will inherit
|
||||||
@ -54,6 +56,7 @@ type Command struct {
|
|||||||
// max lengths of commands' string lengths for use in padding
|
// max lengths of commands' string lengths for use in padding
|
||||||
commandsMaxUseLen int
|
commandsMaxUseLen int
|
||||||
commandsMaxCommandPathLen int
|
commandsMaxCommandPathLen int
|
||||||
|
commandsMaxNameLen int
|
||||||
|
|
||||||
flagErrorBuf *bytes.Buffer
|
flagErrorBuf *bytes.Buffer
|
||||||
cmdErrorBuf *bytes.Buffer
|
cmdErrorBuf *bytes.Buffer
|
||||||
@ -181,6 +184,16 @@ func (c *Command) CommandPathPadding() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var minNamePadding int = 11
|
||||||
|
|
||||||
|
func (c *Command) NamePadding() int {
|
||||||
|
if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {
|
||||||
|
return minNamePadding
|
||||||
|
} else {
|
||||||
|
return c.parent.commandsMaxNameLen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Command) UsageTemplate() string {
|
func (c *Command) UsageTemplate() string {
|
||||||
if c.usageTemplate != "" {
|
if c.usageTemplate != "" {
|
||||||
return c.usageTemplate
|
return c.usageTemplate
|
||||||
@ -195,10 +208,13 @@ Usage: {{if .Runnable}}
|
|||||||
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
|
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
{{.NameAndAliases}}{{end}}
|
{{.NameAndAliases}}
|
||||||
{{ if .HasSubCommands}}
|
{{end}}{{if .HasExample}}
|
||||||
|
Examples:
|
||||||
|
{{ .Example }}
|
||||||
|
{{end}}{{ if .HasSubCommands}}
|
||||||
Available Commands: {{range .Commands}}{{if .Runnable}}
|
Available Commands: {{range .Commands}}{{if .Runnable}}
|
||||||
{{rpad .Use .UsagePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{ if .HasLocalFlags}}Flags:
|
{{ if .HasLocalFlags}}Flags:
|
||||||
{{.LocalFlags.FlagUsages}}{{end}}
|
{{.LocalFlags.FlagUsages}}{{end}}
|
||||||
@ -529,6 +545,10 @@ func (c *Command) AddCommand(cmds ...*Command) {
|
|||||||
if commandPathLen > c.commandsMaxCommandPathLen {
|
if commandPathLen > c.commandsMaxCommandPathLen {
|
||||||
c.commandsMaxCommandPathLen = commandPathLen
|
c.commandsMaxCommandPathLen = commandPathLen
|
||||||
}
|
}
|
||||||
|
nameLen := len(x.Name())
|
||||||
|
if nameLen > c.commandsMaxNameLen {
|
||||||
|
c.commandsMaxNameLen = nameLen
|
||||||
|
}
|
||||||
c.commands = append(c.commands, x)
|
c.commands = append(c.commands, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -669,6 +689,10 @@ func (c *Command) NameAndAliases() string {
|
|||||||
return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")
|
return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Command) HasExample() bool {
|
||||||
|
return len(c.Example) > 0
|
||||||
|
}
|
||||||
|
|
||||||
// Determine if the command is itself runnable
|
// Determine if the command is itself runnable
|
||||||
func (c *Command) Runnable() bool {
|
func (c *Command) Runnable() bool {
|
||||||
return c.Run != nil
|
return c.Run != nil
|
||||||
@ -713,6 +737,50 @@ func (c *Command) LocalFlags() *flag.FlagSet {
|
|||||||
return local
|
return local
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All Flags which were inherited from parents commands
|
||||||
|
func (c *Command) InheritedFlags() *flag.FlagSet {
|
||||||
|
c.mergePersistentFlags()
|
||||||
|
|
||||||
|
local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
|
|
||||||
|
var rmerge func(x *Command)
|
||||||
|
|
||||||
|
rmerge = func(x *Command) {
|
||||||
|
if x.HasPersistentFlags() {
|
||||||
|
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
||||||
|
if local.Lookup(f.Name) == nil {
|
||||||
|
local.AddFlag(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if x.HasParent() {
|
||||||
|
rmerge(x.parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.HasParent() {
|
||||||
|
rmerge(c.parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
|
||||||
|
// All Flags which were not inherited from parent commands
|
||||||
|
func (c *Command) NonInheritedFlags() *flag.FlagSet {
|
||||||
|
c.mergePersistentFlags()
|
||||||
|
|
||||||
|
local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
|
inheritedFlags := c.InheritedFlags()
|
||||||
|
|
||||||
|
c.Flags().VisitAll(func(f *flag.Flag) {
|
||||||
|
if inheritedFlags.Lookup(f.Name) == nil {
|
||||||
|
local.AddFlag(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
|
||||||
// Get the Persistent FlagSet specifically set in the current command
|
// Get the Persistent FlagSet specifically set in the current command
|
||||||
func (c *Command) PersistentFlags() *flag.FlagSet {
|
func (c *Command) PersistentFlags() *flag.FlagSet {
|
||||||
if c.pflags == nil {
|
if c.pflags == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user