aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorspf13 <[email protected]>2013-11-05 19:49:58 -0500
committerspf13 <[email protected]>2013-11-05 19:49:58 -0500
commit5bc978f8eed31e419a5589266ca98a88812147d9 (patch)
tree7e716daeac9ce5d1a0efcbd234dc2af5634a2da4 /flag.go
parent35f8082b75acb5a52bb37d6e34aa2f95d60440a1 (diff)
Fixing bug where invalid trailing short flag would cause panic
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go10
1 files 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:]