Actually skip parsing of flags if SkipFlagParsing is set
Previous just skipped if firstFlagIndex was > -1
This commit is contained in:
parent
c538c376c9
commit
bc3cb33cef
34
command.go
34
command.go
@ -86,27 +86,23 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if firstFlagIndex > -1 && !c.SkipFlagParsing {
|
if !c.SkipFlagParsing {
|
||||||
args := ctx.Args()
|
if firstFlagIndex > -1 {
|
||||||
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
args := ctx.Args()
|
||||||
copy(regularArgs, args[1:firstFlagIndex])
|
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
||||||
|
copy(regularArgs, args[1:firstFlagIndex])
|
||||||
|
|
||||||
var flagArgs []string
|
var flagArgs []string
|
||||||
if terminatorIndex > -1 {
|
if terminatorIndex > -1 {
|
||||||
flagArgs = args[firstFlagIndex:terminatorIndex]
|
flagArgs = args[firstFlagIndex:terminatorIndex]
|
||||||
regularArgs = append(regularArgs, args[terminatorIndex:]...)
|
regularArgs = append(regularArgs, args[terminatorIndex:]...)
|
||||||
|
} else {
|
||||||
|
flagArgs = args[firstFlagIndex:]
|
||||||
|
}
|
||||||
|
|
||||||
|
err = set.Parse(append(flagArgs, regularArgs...))
|
||||||
} else {
|
} else {
|
||||||
flagArgs = args[firstFlagIndex:]
|
err = set.Parse(ctx.Args().Tail())
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user