mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Merge pull request #75 from eparis/CommandLine
Make flags declared outside spf13.pflag persistent flags on the parent
This commit is contained in:
commit
2d5fab043c
1 changed files with 7 additions and 0 deletions
|
@ -948,6 +948,13 @@ func (c *Command) mergePersistentFlags() {
|
||||||
c.PersistentFlags().VisitAll(addtolocal)
|
c.PersistentFlags().VisitAll(addtolocal)
|
||||||
}
|
}
|
||||||
rmerge = func(x *Command) {
|
rmerge = func(x *Command) {
|
||||||
|
if ! x.HasParent() {
|
||||||
|
flag.CommandLine.VisitAll(func(f *flag.Flag) {
|
||||||
|
if x.PersistentFlags().Lookup(f.Name) == nil {
|
||||||
|
x.PersistentFlags().AddFlag(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
if x.HasPersistentFlags() {
|
if x.HasPersistentFlags() {
|
||||||
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
||||||
if c.Flags().Lookup(f.Name) == nil {
|
if c.Flags().Lookup(f.Name) == nil {
|
||||||
|
|
Loading…
Reference in a new issue