Skip to content

Commit

Permalink
Add SkipFlagParsing to app
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Nov 1, 2022
1 parent 4a000ab commit 33a694a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -280,6 +282,7 @@ func (a *App) newRootCommand() *Command {
HelpName: a.HelpName,
CustomHelpTemplate: a.CustomAppHelpTemplate,
categories: a.categories,
SkipFlagParsing: a.SkipFlagParsing,
isRoot: true,
}
}
Expand Down
16 changes: 6 additions & 10 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/godoc-v2.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down

0 comments on commit 33a694a

Please sign in to comment.