Skip to content

Commit d0aeb4d

Browse files
authored
Merge pull request #1562 from dearchap/issue_1114
Fix:(issue_1114) Add SkipFlagParsing to app to allow --
2 parents c3fccc0 + 13cc767 commit d0aeb4d

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

app.go

+3
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

+18
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,24 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
813813
expect(t, args.Get(2), "notAFlagAtAll")
814814
}
815815

816+
func TestApp_SkipFlagParsing(t *testing.T) {
817+
var args Args
818+
819+
app := &App{
820+
SkipFlagParsing: true,
821+
Action: func(c *Context) error {
822+
args = c.Args()
823+
return nil
824+
},
825+
}
826+
827+
_ = app.Run([]string{"", "--", "my-arg", "notAFlagAtAll"})
828+
829+
expect(t, args.Get(0), "--")
830+
expect(t, args.Get(1), "my-arg")
831+
expect(t, args.Get(2), "notAFlagAtAll")
832+
}
833+
816834
func TestApp_VisibleCommands(t *testing.T) {
817835
app := &App{
818836
Commands: []*Command{

godoc-current.txt

+2
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

+2
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)