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,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])
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:]...)
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())
}
}