diff --git a/app.go b/app.go index 3fb5c169ad..ae333a13b2 100644 --- a/app.go +++ b/app.go @@ -113,6 +113,8 @@ type App struct { UseShortOptionHandling bool // Enable suggestions for commands and flags Suggest bool + // Treat all flags as normal arguments if true + SkipFlagParsing bool didSetup bool @@ -280,6 +282,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 4a1dfe6557..f9556ae37e 100644 --- a/app_test.go +++ b/app_test.go @@ -790,22 +790,18 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) { expect(t, args.Get(2), "notAFlagAtAll") } -func TestApp_CommandWithNoFlagImmediatelyBeforeTerminator(t *testing.T) { +func TestApp_SkipFlagParsing(t *testing.T) { var args Args app := &App{ - Commands: []*Command{ - { - Name: "cmd", - Action: func(c *Context) error { - args = c.Args() - return nil - }, - }, + SkipFlagParsing: true, + Action: func(c *Context) error { + 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(1), "my-arg") diff --git a/godoc-current.txt b/godoc-current.txt index fadb7f8629..da142b0afd 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -324,6 +324,8 @@ type App struct { UseShortOptionHandling bool // Enable suggestions for commands and flags Suggest 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 fadb7f8629..da142b0afd 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -324,6 +324,8 @@ type App struct { UseShortOptionHandling bool // Enable suggestions for commands and flags Suggest bool + // Treat all flags as normal arguments if true + SkipFlagParsing bool // Has unexported fields. }