From bc3cb33cef749380a3e1ae4c1a04312521c5f0be Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Sat, 17 Oct 2015 11:36:09 -0700 Subject: [PATCH] Actually skip parsing of flags if SkipFlagParsing is set Previous just skipped if firstFlagIndex was > -1 --- command.go | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/command.go b/command.go index 7a1dcab..c63b049 100644 --- a/command.go +++ b/command.go @@ -86,27 +86,23 @@ func (c Command) Run(ctx *Context) error { } var err error - if firstFlagIndex > -1 && !c.SkipFlagParsing { - args := ctx.Args() - regularArgs := make([]string, len(args[1:firstFlagIndex])) - copy(regularArgs, args[1:firstFlagIndex]) - - var flagArgs []string - if terminatorIndex > -1 { - flagArgs = args[firstFlagIndex:terminatorIndex] - regularArgs = append(regularArgs, args[terminatorIndex:]...) + if !c.SkipFlagParsing { + if firstFlagIndex > -1 { + args := ctx.Args() + regularArgs := make([]string, len(args[1:firstFlagIndex])) + copy(regularArgs, args[1:firstFlagIndex]) + + var flagArgs []string + if terminatorIndex > -1 { + flagArgs = args[firstFlagIndex:terminatorIndex] + regularArgs = append(regularArgs, args[terminatorIndex:]...) + } else { + flagArgs = args[firstFlagIndex:] + } + + err = set.Parse(append(flagArgs, regularArgs...)) } else { - flagArgs = args[firstFlagIndex:] - } - - err = set.Parse(append(flagArgs, regularArgs...)) - } else { - 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 + err = set.Parse(ctx.Args().Tail()) } }