Skip to content

Commit 13cc767

Browse files
committed
Add SkipFlagParsing to app
1 parent bb82056 commit 13cc767

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type App struct {
116116
// Allows global flags set by libraries which use flag.XXXVar(...) directly
117117
// to be parsed through this library
118118
AllowExtFlags bool
119+
// Treat all flags as normal arguments if true
120+
SkipFlagParsing bool
119121

120122
didSetup bool
121123

@@ -285,6 +287,7 @@ func (a *App) newRootCommand() *Command {
285287
HelpName: a.HelpName,
286288
CustomHelpTemplate: a.CustomAppHelpTemplate,
287289
categories: a.categories,
290+
SkipFlagParsing: a.SkipFlagParsing,
288291
isRoot: true,
289292
}
290293
}

app_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,22 +813,18 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
813813
expect(t, args.Get(2), "notAFlagAtAll")
814814
}
815815

816-
func TestApp_CommandWithNoFlagImmediatelyBeforeTerminator(t *testing.T) {
816+
func TestApp_SkipFlagParsing(t *testing.T) {
817817
var args Args
818818

819819
app := &App{
820-
Commands: []*Command{
821-
{
822-
Name: "cmd",
823-
Action: func(c *Context) error {
824-
args = c.Args()
825-
return nil
826-
},
827-
},
820+
SkipFlagParsing: true,
821+
Action: func(c *Context) error {
822+
args = c.Args()
823+
return nil
828824
},
829825
}
830826

831-
_ = app.Run([]string{"", "cmd", "--", "my-arg", "notAFlagAtAll"})
827+
_ = app.Run([]string{"", "--", "my-arg", "notAFlagAtAll"})
832828

833829
expect(t, args.Get(0), "--")
834830
expect(t, args.Get(1), "my-arg")

godoc-current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ type App struct {
327327
// Allows global flags set by libraries which use flag.XXXVar(...) directly
328328
// to be parsed through this library
329329
AllowExtFlags bool
330+
// Treat all flags as normal arguments if true
331+
SkipFlagParsing bool
330332

331333
// Has unexported fields.
332334
}

testdata/godoc-v2.x.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ type App struct {
327327
// Allows global flags set by libraries which use flag.XXXVar(...) directly
328328
// to be parsed through this library
329329
AllowExtFlags bool
330+
// Treat all flags as normal arguments if true
331+
SkipFlagParsing bool
330332

331333
// Has unexported fields.
332334
}

0 commit comments

Comments
 (0)