Merge commit 'd0aeb4d' into v3-porting

This commit is contained in:
Dan Buch 2022-11-07 08:35:19 -05:00
commit c6318ceaf8
Signed by: meatballhat
GPG Key ID: A12F782281063434
4 changed files with 25 additions and 0 deletions

3
app.go
View File

@ -116,6 +116,8 @@ type App struct {
// Allows global flags set by libraries which use flag.XXXVar(...) directly // Allows global flags set by libraries which use flag.XXXVar(...) directly
// to be parsed through this library // to be parsed through this library
AllowExtFlags bool AllowExtFlags bool
// Treat all flags as normal arguments if true
SkipFlagParsing bool
didSetup bool didSetup bool
@ -283,6 +285,7 @@ func (a *App) newRootCommand() *Command {
HelpName: a.HelpName, HelpName: a.HelpName,
CustomHelpTemplate: a.CustomAppHelpTemplate, CustomHelpTemplate: a.CustomAppHelpTemplate,
categories: a.categories, categories: a.categories,
SkipFlagParsing: a.SkipFlagParsing,
isRoot: true, isRoot: true,
} }
} }

View File

@ -813,6 +813,24 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
expect(t, args.Get(2), "notAFlagAtAll") 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) { func TestApp_VisibleCommands(t *testing.T) {
app := &App{ app := &App{
Commands: []*Command{ Commands: []*Command{

View File

@ -325,6 +325,8 @@ type App struct {
// Allows global flags set by libraries which use flag.XXXVar(...) directly // Allows global flags set by libraries which use flag.XXXVar(...) directly
// to be parsed through this library // to be parsed through this library
AllowExtFlags bool AllowExtFlags bool
// Treat all flags as normal arguments if true
SkipFlagParsing bool
// Has unexported fields. // Has unexported fields.
} }

View File

@ -325,6 +325,8 @@ type App struct {
// Allows global flags set by libraries which use flag.XXXVar(...) directly // Allows global flags set by libraries which use flag.XXXVar(...) directly
// to be parsed through this library // to be parsed through this library
AllowExtFlags bool AllowExtFlags bool
// Treat all flags as normal arguments if true
SkipFlagParsing bool
// Has unexported fields. // Has unexported fields.
} }