When skipping flag parsing, still parse into arguments

Fool the FlagSet into thinking that all arguments are actually
arguments rather than attempting to parse them as flags.
This commit is contained in:
Jesse Szwedko 2015-10-26 21:40:03 -07:00
parent bc3cb33cef
commit 6191d931b7

View File

@ -74,6 +74,8 @@ func (c Command) Run(ctx *Context) error {
set := flagSet(c.Name, c.Flags)
set.SetOutput(ioutil.Discard)
var err error
if !c.SkipFlagParsing {
firstFlagIndex := -1
terminatorIndex := -1
for index, arg := range ctx.Args() {
@ -85,8 +87,6 @@ func (c Command) Run(ctx *Context) error {
}
}
var err error
if !c.SkipFlagParsing {
if firstFlagIndex > -1 {
args := ctx.Args()
regularArgs := make([]string, len(args[1:firstFlagIndex]))
@ -104,6 +104,10 @@ func (c Command) Run(ctx *Context) error {
} else {
err = set.Parse(ctx.Args().Tail())
}
} else {
if c.SkipFlagParsing {
err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...))
}
}
if err != nil {