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:
parent
bc3cb33cef
commit
6191d931b7
@ -74,6 +74,8 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
set := flagSet(c.Name, c.Flags)
|
set := flagSet(c.Name, c.Flags)
|
||||||
set.SetOutput(ioutil.Discard)
|
set.SetOutput(ioutil.Discard)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if !c.SkipFlagParsing {
|
||||||
firstFlagIndex := -1
|
firstFlagIndex := -1
|
||||||
terminatorIndex := -1
|
terminatorIndex := -1
|
||||||
for index, arg := range ctx.Args() {
|
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 {
|
if firstFlagIndex > -1 {
|
||||||
args := ctx.Args()
|
args := ctx.Args()
|
||||||
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
||||||
@ -104,6 +104,10 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
} else {
|
} else {
|
||||||
err = set.Parse(ctx.Args().Tail())
|
err = set.Parse(ctx.Args().Tail())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if c.SkipFlagParsing {
|
||||||
|
err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user