Commit f98cd70c authored by Brendan Burns's avatar Brendan Burns

Update the cobra and pflag libraries with upstream fixes.

parent 232796db
......@@ -357,11 +357,11 @@
},
{
"ImportPath": "github.com/spf13/cobra",
"Rev": "f8e1ec56bdd7494d309c69681267859a6bfb7549"
"Rev": "9e7273d5469dd5e04a35fd8823ba510117448c0b"
},
{
"ImportPath": "github.com/spf13/pflag",
"Rev": "370c3171201099fa6b466db45c8a032cbce33d8d"
"Rev": "11b7cf8387a31f278486eaad758162830eca8c73"
},
{
"ImportPath": "github.com/stretchr/objx",
......
......@@ -11,11 +11,14 @@ var _ = fmt.Println
var tp, te, tt, t1 []string
var flagb1, flagb2, flagb3, flagbr bool
var flags1, flags2, flags3 string
var flags1, flags2a, flags2b, flags3 string
var flagi1, flagi2, flagi3, flagir int
var globalFlag1 bool
var flagEcho, rootcalled bool
const strtwoParentHelp = "help message for parent flag strtwo"
const strtwoChildHelp = "help message for child flag strtwo"
var cmdPrint = &Command{
Use: "print [string to print]",
Short: "Print anything to the screen",
......@@ -72,11 +75,12 @@ func flagInit() {
cmdRootNoRun.ResetFlags()
cmdRootSameName.ResetFlags()
cmdRootWithRun.ResetFlags()
cmdRootNoRun.PersistentFlags().StringVarP(&flags2a, "strtwo", "t", "two", strtwoParentHelp)
cmdEcho.Flags().IntVarP(&flagi1, "intone", "i", 123, "help message for flag intone")
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")
cmdTimes.PersistentFlags().StringVarP(&flags2, "strtwo", "t", "two", "help message for flag strtwo")
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")
cmdTimes.Flags().BoolVarP(&flagb2, "booltwo", "c", false, "help message for flag booltwo")
......@@ -377,10 +381,21 @@ func TestChildCommandFlags(t *testing.T) {
t.Errorf("invalid flag should generate error")
}
if !strings.Contains(r.Output, "intone=123") {
if !strings.Contains(r.Output, "unknown shorthand flag") {
t.Errorf("Wrong error message displayed, \n %s", r.Output)
}
// Testing with persistent flag overwritten by child
noRRSetupTest("echo times --strtwo=child one two")
if flags2b != "child" {
t.Errorf("flag value should be child, %s given", flags2b)
}
if flags2a != "two" {
t.Errorf("unset flag should have default value, expecting two, given %s", flags2a)
}
// Testing flag with invalid input
r = noRRSetupTest("echo -i10E")
......@@ -437,6 +452,13 @@ func TestHelpCommand(t *testing.T) {
checkResultContains(t, r, cmdTimes.Long)
}
func TestChildCommandHelp(t *testing.T) {
c := noRRSetupTest("print --help")
checkResultContains(t, c, strtwoParentHelp)
r := noRRSetupTest("echo times --help")
checkResultContains(t, r, strtwoChildHelp)
}
func TestRunnableRootCommand(t *testing.T) {
fullSetupTest("")
......@@ -486,6 +508,26 @@ func TestRootHelp(t *testing.T) {
}
func TestFlagAccess(t *testing.T) {
initialize()
local := cmdTimes.LocalFlags()
inherited := cmdTimes.InheritedFlags()
for _, f := range []string{"inttwo", "strtwo", "booltwo"} {
if local.Lookup(f) == nil {
t.Errorf("LocalFlags expected to contain %s, Got: nil", f)
}
}
if inherited.Lookup("strone") == nil {
t.Errorf("InheritedFlags expected to contain strone, Got: nil")
}
if inherited.Lookup("strtwo") != nil {
t.Errorf("InheritedFlags shouldn not contain overwritten flag strtwo")
}
}
func TestRootNoCommandHelp(t *testing.T) {
x := rootOnlySetupTest("--help")
......
......@@ -9,7 +9,7 @@ import (
"strconv"
"testing"
. "github.com/ogier/pflag"
. "github.com/spf13/pflag"
)
// This value can be a boolean ("true", "false") or "maybe"
......
......@@ -11,7 +11,7 @@ import (
"strings"
"time"
flag "github.com/ogier/pflag"
flag "github.com/spf13/pflag"
)
// Example 1: A single string flag called "species" with default value "gopher".
......
......@@ -498,6 +498,7 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error)
if len(args) == 0 {
return
}
return
}
if alreadythere {
if bv, ok := flag.Value.(boolFlag); ok && bv.IsBoolFlag() {
......@@ -551,6 +552,9 @@ func (f *FlagSet) parseArgs(args []string) (err error) {
} else {
args, err = f.parseShortArg(s, args)
}
if err != nil {
return
}
}
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment