aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorchilde <[email protected]>2018-04-03 19:55:18 +0800
committerEric Paris <[email protected]>2018-04-03 07:55:18 -0400
commit1ce0cc6db4029d97571db82f85092fccedb572ce (patch)
tree8c833fbe5daaefd3898388d4a979a696d151302d /flag.go
parent1cd4a0c365d95803411bec89fb7b76bade17053b (diff)
make x.Parsed() return true after AddGoFlagSet(x) and pflag.Parse() (#162)
* make GoFlagSets.Parsed() true after pflag.Parse some third part lib such as glog use go flag package, and its some actions depends on if goflag.Parsed(). * add test case for goflag.CommandLine.Parsed() * add comment to goflag.CommandLine.Parsed test case
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/flag.go b/flag.go
index f0acbb8..e4e0c94 100644
--- a/flag.go
+++ b/flag.go
@@ -101,6 +101,7 @@ package pflag
import (
"bytes"
"errors"
+ goflag "flag"
"fmt"
"io"
"os"
@@ -162,6 +163,8 @@ type FlagSet struct {
output io.Writer // nil means stderr; use out() accessor
interspersed bool // allow interspersed option/non-option args
normalizeNameFunc func(f *FlagSet, name string) NormalizedName
+
+ addedGoFlagSets []*goflag.FlagSet
}
// A Flag represents the state of a flag.
@@ -1098,6 +1101,11 @@ func (f *FlagSet) parseArgs(args []string, fn parseFunc) (err error) {
// are defined and before flags are accessed by the program.
// The return value will be ErrHelp if -help was set but not defined.
func (f *FlagSet) Parse(arguments []string) error {
+ if f.addedGoFlagSets != nil {
+ for _, goFlagSet := range f.addedGoFlagSets {
+ goFlagSet.Parse(nil)
+ }
+ }
f.parsed = true
if len(arguments) < 0 {