From 13cc7677ab2adc0c11bc8eec3defe83eea0f4599 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Tue, 1 Nov 2022 17:55:45 -0400 Subject: [PATCH] Add SkipFlagParsing to app --- app.go | 3 +++ app_test.go | 16 ++++++---------- godoc-current.txt | 2 ++ testdata/godoc-v2.x.txt | 2 ++ 4 files changed, 13 insertions(+), 10 deletions(-) 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 90994d15b7..7091c40ef9 100644 --- a/app_test.go +++ b/app_test.go @@ -813,22 +813,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 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. }