FIx: Allow ext flags to be opt-out by default rather than opt-in

This commit is contained in:
Naveen Gogineni
2022-11-01 17:44:12 -04:00
parent ae8d932413
commit fb3a9cebb4
4 changed files with 41 additions and 7 deletions

19
app.go
View File

@@ -113,6 +113,9 @@ type App struct {
UseShortOptionHandling bool
// Enable suggestions for commands and flags
Suggest bool
// Allows global flags set by libraries which use flag.XXXVar(...) directly
// to be parsed through this library
AllowExtFlags bool
didSetup bool
@@ -199,13 +202,15 @@ func (a *App) Setup() {
a.ErrWriter = os.Stderr
}
// add global flags added by other packages
flag.VisitAll(func(f *flag.Flag) {
// skip test flags
if !strings.HasPrefix(f.Name, ignoreFlagPrefix) {
a.Flags = append(a.Flags, &extFlag{f})
}
})
if a.AllowExtFlags {
// add global flags added by other packages
flag.VisitAll(func(f *flag.Flag) {
// skip test flags
if !strings.HasPrefix(f.Name, ignoreFlagPrefix) {
a.Flags = append(a.Flags, &extFlag{f})
}
})
}
var newCommands []*Command