diff --git a/app.go b/app.go index effe205442..e7f79c5130 100644 --- a/app.go +++ b/app.go @@ -116,6 +116,8 @@ type App struct { // Allows global flags set by libraries which use flag.XXXVar(...) directly // to be parsed through this library AllowExtFlags bool + // Treat all flags as normal arguments if true + SkipFlagParsing bool didSetup bool @@ -285,6 +287,7 @@ func (a *App) newRootCommand() *Command { HelpName: a.HelpName, CustomHelpTemplate: a.CustomAppHelpTemplate, categories: a.categories, + SkipFlagParsing: a.SkipFlagParsing, isRoot: true, } } diff --git a/app_test.go b/app_test.go index e2b31e910d..7091c40ef9 100644 --- a/app_test.go +++ b/app_test.go @@ -813,6 +813,24 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) { expect(t, args.Get(2), "notAFlagAtAll") } +func TestApp_SkipFlagParsing(t *testing.T) { + var args Args + + app := &App{ + SkipFlagParsing: true, + Action: func(c *Context) error { + args = c.Args() + return nil + }, + } + + _ = app.Run([]string{"", "--", "my-arg", "notAFlagAtAll"}) + + expect(t, args.Get(0), "--") + expect(t, args.Get(1), "my-arg") + expect(t, args.Get(2), "notAFlagAtAll") +} + func TestApp_VisibleCommands(t *testing.T) { app := &App{ Commands: []*Command{ diff --git a/godoc-current.txt b/godoc-current.txt index 5b67f953c7..54424fb1e6 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -327,6 +327,8 @@ type App struct { // Allows global flags set by libraries which use flag.XXXVar(...) directly // to be parsed through this library AllowExtFlags bool + // Treat all flags as normal arguments if true + SkipFlagParsing bool // Has unexported fields. } diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index 5b67f953c7..54424fb1e6 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -327,6 +327,8 @@ type App struct { // Allows global flags set by libraries which use flag.XXXVar(...) directly // to be parsed through this library AllowExtFlags bool + // Treat all flags as normal arguments if true + SkipFlagParsing bool // Has unexported fields. }