From 5bc978f8eed31e419a5589266ca98a88812147d9 Mon Sep 17 00:00:00 2001 From: spf13 Date: Tue, 5 Nov 2013 19:49:58 -0500 Subject: Fixing bug where invalid trailing short flag would cause panic --- flag.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/flag.go b/flag.go index 9b25302..bce00d1 100644 --- a/flag.go +++ b/flag.go @@ -993,15 +993,11 @@ func (f *FlagSet) parseLongArg(s string, args []string) (a []string, err error) func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error) { a = args shorthands := s[1:] - //fmt.Println("shorthands", shorthands) - //fmt.Print("all shorthands", f.shorthands) + for i := 0; i < len(shorthands); i++ { c := shorthands[i] - //fmt.Println("c", c) flag, alreadythere := f.shorthands[c] - //fmt.Println(alreadythere) if !alreadythere { - //fmt.Println("not there") if c == 'h' { // special case for nice help message. f.usage() err = ErrHelp @@ -1009,6 +1005,9 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error) } //TODO continue on error err = f.failf("unknown shorthand flag: %q in -%s", c, shorthands) + if len(args) == 0 { + return + } } if alreadythere { if _, ok := flag.Value.(*boolValue); ok { @@ -1039,7 +1038,6 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error) } func (f *FlagSet) parseArgs(args []string) (err error) { - //fmt.Println(args) for len(args) > 0 { s := args[0] args = args[1:] -- cgit v1.2.3