diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7a1bf0768e8..93635982675 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -235,7 +235,7 @@ }, { "ImportPath": "github.com/spf13/pflag", - "Rev": "f82776d6cc998e3c026baef7b24409ff49fe5c8d" + "Rev": "370c3171201099fa6b466db45c8a032cbce33d8d" }, { "ImportPath": "github.com/stretchr/objx", diff --git a/Godeps/_workspace/src/github.com/spf13/pflag/flag.go b/Godeps/_workspace/src/github.com/spf13/pflag/flag.go index 2e4cac08493..ad65ddad2df 100644 --- a/Godeps/_workspace/src/github.com/spf13/pflag/flag.go +++ b/Godeps/_workspace/src/github.com/spf13/pflag/flag.go @@ -543,6 +543,11 @@ func (f *FlagSet) parseArgs(args []string) (err error) { if s[1] == '-' { args, err = f.parseLongArg(s, args) + + if len(s) == 2 { + // stop parsing after -- + break + } } else { args, err = f.parseShortArg(s, args) } diff --git a/Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go b/Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go index 47865bd96ba..a33c601bc59 100644 --- a/Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go +++ b/Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go @@ -197,8 +197,8 @@ func TestShorthand(t *testing.T) { notaflag, } f.SetOutput(ioutil.Discard) - if err := f.Parse(args); err == nil { - t.Error("--i-look-like-a-flag should throw an error") + if err := f.Parse(args); err != nil { + t.Error("expected no error, got ", err) } if !f.Parsed() { t.Error("f.Parse() = false after Parse") @@ -356,3 +356,37 @@ func TestNoInterspersed(t *testing.T) { t.Fatal("expected interspersed options/non-options to fail") } } + +func TestTermination(t *testing.T) { + f := NewFlagSet("termination", ContinueOnError) + boolFlag := f.BoolP("bool", "l", false, "bool value") + if f.Parsed() { + t.Error("f.Parse() = true before Parse") + } + arg1 := "ls" + arg2 := "-l" + args := []string{ + "--", + arg1, + arg2, + } + f.SetOutput(ioutil.Discard) + if err := f.Parse(args); err != nil { + t.Fatal("expected no error; got ", err) + } + if !f.Parsed() { + t.Error("f.Parse() = false after Parse") + } + if *boolFlag { + t.Error("expected boolFlag=false, got true") + } + if len(f.Args()) != 2 { + t.Errorf("expected 2 arguments, got %d: %v", len(f.Args()), f.Args()) + } + if f.Args()[0] != arg1 { + t.Errorf("expected argument %q got %q", arg1, f.Args()[0]) + } + if f.Args()[1] != arg2 { + t.Errorf("expected argument %q got %q", arg2, f.Args()[1]) + } +}