Skip to content

Commit

Permalink
Merge pull request #1562 from dearchap/issue_1114
Browse files Browse the repository at this point in the history
Fix:(issue_1114) Add SkipFlagParsing to app to allow --
  • Loading branch information
dearchap committed Nov 2, 2022
2 parents c3fccc0 + 13cc767 commit d0aeb4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app.go
Expand Up @@ -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

Expand Down Expand Up @@ -285,6 +287,7 @@ func (a *App) newRootCommand() *Command {
HelpName: a.HelpName,
CustomHelpTemplate: a.CustomAppHelpTemplate,
categories: a.categories,
SkipFlagParsing: a.SkipFlagParsing,
isRoot: true,
}
}
Expand Down
18 changes: 18 additions & 0 deletions app_test.go
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions godoc-current.txt
Expand Up @@ -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.
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/godoc-v2.x.txt
Expand Up @@ -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.
}
Expand Down

0 comments on commit d0aeb4d

Please sign in to comment.