Add SkipFlagParsing to app
This commit is contained in:
parent
bb820560d9
commit
13cc7677ab
3
app.go
3
app.go
@ -116,6 +116,8 @@ type App struct {
|
|||||||
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
||||||
// to be parsed through this library
|
// to be parsed through this library
|
||||||
AllowExtFlags bool
|
AllowExtFlags bool
|
||||||
|
// Treat all flags as normal arguments if true
|
||||||
|
SkipFlagParsing bool
|
||||||
|
|
||||||
didSetup bool
|
didSetup bool
|
||||||
|
|
||||||
@ -285,6 +287,7 @@ func (a *App) newRootCommand() *Command {
|
|||||||
HelpName: a.HelpName,
|
HelpName: a.HelpName,
|
||||||
CustomHelpTemplate: a.CustomAppHelpTemplate,
|
CustomHelpTemplate: a.CustomAppHelpTemplate,
|
||||||
categories: a.categories,
|
categories: a.categories,
|
||||||
|
SkipFlagParsing: a.SkipFlagParsing,
|
||||||
isRoot: true,
|
isRoot: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
app_test.go
16
app_test.go
@ -813,22 +813,18 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
|
|||||||
expect(t, args.Get(2), "notAFlagAtAll")
|
expect(t, args.Get(2), "notAFlagAtAll")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApp_CommandWithNoFlagImmediatelyBeforeTerminator(t *testing.T) {
|
func TestApp_SkipFlagParsing(t *testing.T) {
|
||||||
var args Args
|
var args Args
|
||||||
|
|
||||||
app := &App{
|
app := &App{
|
||||||
Commands: []*Command{
|
SkipFlagParsing: true,
|
||||||
{
|
Action: func(c *Context) error {
|
||||||
Name: "cmd",
|
args = c.Args()
|
||||||
Action: func(c *Context) error {
|
return nil
|
||||||
args = c.Args()
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.Run([]string{"", "cmd", "--", "my-arg", "notAFlagAtAll"})
|
_ = app.Run([]string{"", "--", "my-arg", "notAFlagAtAll"})
|
||||||
|
|
||||||
expect(t, args.Get(0), "--")
|
expect(t, args.Get(0), "--")
|
||||||
expect(t, args.Get(1), "my-arg")
|
expect(t, args.Get(1), "my-arg")
|
||||||
|
@ -327,6 +327,8 @@ type App struct {
|
|||||||
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
||||||
// to be parsed through this library
|
// to be parsed through this library
|
||||||
AllowExtFlags bool
|
AllowExtFlags bool
|
||||||
|
// Treat all flags as normal arguments if true
|
||||||
|
SkipFlagParsing bool
|
||||||
|
|
||||||
// Has unexported fields.
|
// Has unexported fields.
|
||||||
}
|
}
|
||||||
|
2
testdata/godoc-v2.x.txt
vendored
2
testdata/godoc-v2.x.txt
vendored
@ -327,6 +327,8 @@ type App struct {
|
|||||||
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
// Allows global flags set by libraries which use flag.XXXVar(...) directly
|
||||||
// to be parsed through this library
|
// to be parsed through this library
|
||||||
AllowExtFlags bool
|
AllowExtFlags bool
|
||||||
|
// Treat all flags as normal arguments if true
|
||||||
|
SkipFlagParsing bool
|
||||||
|
|
||||||
// Has unexported fields.
|
// Has unexported fields.
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user