diff options
| author | Eric Paris <[email protected]> | 2015-08-15 16:05:51 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-08-15 16:12:29 -0400 |
| commit | e0e7ef766bf91748c5c55258e3773edaea7ed5f4 (patch) | |
| tree | 6b7b45fb16d399e64949d036e5bfdc6be79586f6 /flag.go | |
| parent | 4b69d21313e8b16259f8fdac37156283b254c84b (diff) | |
New AddFlagSet function on FlagSet
This function allows one to create a different FlagSets and then easily
merge them together.
Diffstat (limited to 'flag.go')
| -rw-r--r-- | flag.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -524,6 +524,19 @@ func (f *FlagSet) AddFlag(flag *Flag) { f.shorthands[c] = flag } +// AddFlagSet adds one FlagSet to another. If a flag is already present in f +// the flag from newSet will be ignored +func (f *FlagSet) AddFlagSet(newSet *FlagSet) { + if newSet == nil { + return + } + newSet.VisitAll(func(flag *Flag) { + if f.Lookup(flag.Name) == nil { + f.AddFlag(flag) + } + }) +} + // Var defines a flag with the specified name and usage string. The type and // value of the flag are represented by the first argument, of type Value, which // typically holds a user-defined implementation of Value. For instance, the |
