Actually skip parsing of flags if SkipFlagParsing is set

Previous just skipped if firstFlagIndex was > -1
This commit is contained in:
Jesse Szwedko 2015-10-17 11:36:09 -07:00
parent c538c376c9
commit bc3cb33cef

View File

@ -86,7 +86,8 @@ func (c Command) Run(ctx *Context) error {
} }
var err error var err error
if firstFlagIndex > -1 && !c.SkipFlagParsing { if !c.SkipFlagParsing {
if firstFlagIndex > -1 {
args := ctx.Args() args := ctx.Args()
regularArgs := make([]string, len(args[1:firstFlagIndex])) regularArgs := make([]string, len(args[1:firstFlagIndex]))
copy(regularArgs, args[1:firstFlagIndex]) copy(regularArgs, args[1:firstFlagIndex])
@ -102,11 +103,6 @@ func (c Command) Run(ctx *Context) error {
err = set.Parse(append(flagArgs, regularArgs...)) err = set.Parse(append(flagArgs, regularArgs...))
} else { } else {
err = set.Parse(ctx.Args().Tail()) err = set.Parse(ctx.Args().Tail())
// Work around issue where if the first arg in ctx.Args.Tail()
// is a flag, set.Parse returns an error
if c.SkipFlagParsing {
err = nil
} }
} }