Skip to content
Myr

Make flags declared outside spf13.pflag persistent flags on the parent

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Some projects pick up flags from other projects they include. A great example would be projects that use glog and thus get all of those flags. Kubernetes, for example, merges those flags manually into its commands. This was reported in https://github.com/spf13/cobra/issues/44 What this patch does is merge those flags into the PersistentFlags on the highest parent. This allows kubernetes to stop having to merge things themselves...

authored by Eric Paris · committed by Eric Paris · parent e784a59 · Browse files · 1 file+7 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−0 removed

  • other:+7 added−0 removed

1 file+7 added−0 removed

modified:command.go+7 added
940 unmodified lines
941 c.Flags().VisitAll(addtolocal)942 c.PersistentFlags().VisitAll(addtolocal)943 }944 rmerge = func(x *Command) {945 if ! x.HasParent() {946 flag.CommandLine.VisitAll(func(f *flag.Flag) {947 if x.PersistentFlags().Lookup(f.Name) == nil {948 x.PersistentFlags().AddFlag(f)949 }950 })951 }952 if x.HasPersistentFlags() {953 x.PersistentFlags().VisitAll(func(f *flag.Flag) {954 if c.Flags().Lookup(f.Name) == nil {955 c.Flags().AddFlag(f)
10 unmodified lines