Update spf13/cobra with recent commits.

This commit is contained in:
Brendan Burns 2015-03-23 15:09:20 -07:00
parent c66caa5336
commit a18ec3be88
7 changed files with 46 additions and 26 deletions

2
Godeps/Godeps.json generated
View File

@ -387,7 +387,7 @@
},
{
"ImportPath": "github.com/spf13/cobra",
"Rev": "9e7273d5469dd5e04a35fd8823ba510117448c0b"
"Rev": "79bd93d369fb73d640179208d4e2b1a748915567"
},
{
"ImportPath": "github.com/spf13/pflag",

View File

@ -10,7 +10,7 @@ import (
var _ = fmt.Println
var tp, te, tt, t1 []string
var flagb1, flagb2, flagb3, flagbr bool
var flagb1, flagb2, flagb3, flagbr, flagbp bool
var flags1, flags2a, flags2b, flags3 string
var flagi1, flagi2, flagi3, flagir int
var globalFlag1 bool
@ -80,6 +80,7 @@ func flagInit() {
cmdTimes.Flags().IntVarP(&flagi2, "inttwo", "j", 234, "help message for flag inttwo")
cmdPrint.Flags().IntVarP(&flagi3, "intthree", "i", 345, "help message for flag intthree")
cmdEcho.PersistentFlags().StringVarP(&flags1, "strone", "s", "one", "help message for flag strone")
cmdEcho.PersistentFlags().BoolVarP(&flagbp, "persistentbool", "p", false, "help message for flag persistentbool")
cmdTimes.PersistentFlags().StringVarP(&flags2b, "strtwo", "t", "2", strtwoChildHelp)
cmdPrint.PersistentFlags().StringVarP(&flags3, "strthree", "s", "three", "help message for flag strthree")
cmdEcho.Flags().BoolVarP(&flagb1, "boolone", "b", true, "help message for flag boolone")
@ -417,19 +418,21 @@ func TestTrailingCommandFlags(t *testing.T) {
}
func TestPersistentFlags(t *testing.T) {
fullSetupTest("echo -s something more here")
fullSetupTest("echo -s something -p more here")
// persistentFlag should act like normal flag on it's own command
if strings.Join(te, " ") != "more here" {
t.Errorf("flags didn't leave proper args remaining..%s given", te)
}
// persistentFlag should act like normal flag on it's own command
if flags1 != "something" {
t.Errorf("string flag didn't get correct value, had %v", flags1)
}
if !flagbp {
t.Errorf("persistent bool flag not parsed correctly. Expected true, had %v", flagbp)
}
fullSetupTest("echo times -s again -c test here")
// persistentFlag should act like normal flag on it's own command
fullSetupTest("echo times -s again -c -p test here")
if strings.Join(tt, " ") != "test here" {
t.Errorf("flags didn't leave proper args remaining..%s given", tt)
@ -439,8 +442,11 @@ func TestPersistentFlags(t *testing.T) {
t.Errorf("string flag didn't get correct value, had %v", flags1)
}
if flagb2 != true {
t.Errorf("local flag not parsed correctly. Expected false, had %v", flagb2)
if !flagb2 {
t.Errorf("local flag not parsed correctly. Expected true, had %v", flagb2)
}
if !flagbp {
t.Errorf("persistent bool flag not parsed correctly. Expected true, had %v", flagbp)
}
}

View File

@ -79,7 +79,7 @@ func (c *Command) SetArgs(a []string) {
c.args = a
}
func (c *Command) Out() io.Writer {
func (c *Command) getOut(def io.Writer) io.Writer {
if c.output != nil {
return *c.output
}
@ -87,10 +87,18 @@ func (c *Command) Out() io.Writer {
if c.HasParent() {
return c.parent.Out()
} else {
return os.Stderr
return def
}
}
func (c *Command) Out() io.Writer {
return c.getOut(os.Stderr)
}
func (c *Command) getOutOrStdout() io.Writer {
return c.getOut(os.Stdout)
}
// SetOutput sets the destination for usage and error messages.
// If output is nil, os.Stderr is used.
func (c *Command) SetOutput(output io.Writer) {
@ -212,9 +220,11 @@ Usage: {{if .Runnable}}
Aliases:
{{.NameAndAliases}}
{{end}}{{if .HasExample}}
Examples:
{{ .Example }}
{{end}}{{ if .HasSubCommands}}
Available Commands: {{range .Commands}}{{if .Runnable}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
{{end}}
@ -238,7 +248,7 @@ func (c *Command) HelpTemplate() string {
if c.HasParent() {
return c.parent.HelpTemplate()
} else {
return `{{.Long | trim}}
return `{{with or .Long .Short }}{{. | trim}}{{end}}
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}
`
}
@ -275,6 +285,7 @@ func stripFlags(args []string, c *Command) []string {
if len(args) < 1 {
return args
}
c.mergePersistentFlags()
commands := []string{}
@ -657,7 +668,7 @@ func (c *Command) Usage() error {
// by the default HelpFunc in the commander
func (c *Command) Help() error {
c.mergePersistentFlags()
err := tmpl(c.Out(), c.HelpTemplate(), c)
err := tmpl(c.getOutOrStdout(), c.HelpTemplate(), c)
return err
}

View File

@ -11,6 +11,12 @@ Print available API versions.
kubectl apiversions
```
### Options
```
-h, --help=false: help for apiversions
```
### Options inherrited from parent commands
```
@ -22,7 +28,6 @@ kubectl apiversions
--client-key="": Path to a client key file for TLS.
--cluster="": The name of the kubeconfig cluster to use
--context="": The name of the kubeconfig context to use
-h, --help=false: help for kubectl
--insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.
--kubeconfig="": Path to the kubeconfig file to use for CLI requests.
--log_backtrace_at=:0: when logging hits line file:N, emit a stack trace

View File

@ -31,11 +31,8 @@ $ kubectl expose streamer --port=4100 --protocol=udp --service-name=video-stream
--create-external-load-balancer=false: If true, create an external load balancer for this service. Implementation is cloud provider dependent. Default is 'false'.
--dry-run=false: If true, only print the object that would be sent, without creating it.
--generator="service/v1": The name of the API generator to use. Default is 'service/v1'.
<<<<<<< HEAD
-l, --labels="": Labels to apply to the service created by this call.
=======
-h, --help=false: help for expose
>>>>>>> Revert "Revert "Update cobra/pflag. Also update generated kubectl documentation.""
-l, --labels="": Labels to apply to the service created by this call.
--no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile.
--output-version="": Output the formatted object with the given version (default api-version).

View File

@ -16,6 +16,12 @@ kubectl apiversions \- Print available API versions.
Print available API versions.
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP=false
help for apiversions
.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
\fB\-\-alsologtostderr\fP=false
@ -49,10 +55,6 @@ Print available API versions.
\fB\-\-context\fP=""
The name of the kubeconfig context to use
.PP
\fB\-h\fP, \fB\-\-help\fP=false
help for kubectl
.PP
\fB\-\-insecure\-skip\-tls\-verify\fP=false
If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.

View File

@ -38,13 +38,12 @@ as the selector for a new Service on the specified port.
The name of the API generator to use. Default is 'service/v1'.
.PP
<<<<<<< HEAD
\fB\-l\fP, \fB\-\-labels\fP=""
Labels to apply to the service created by this call.
=======
\fB\-h\fP, \fB\-\-help\fP=false
help for expose
>>>>>>> Revert "Revert "Update cobra/pflag. Also update generated kubectl documentation.""
.PP
\fB\-l\fP, \fB\-\-labels\fP=""
Labels to apply to the service created by this call.
.PP
\fB\-\-no\-headers\fP=false