Skip to content
Myr

new InheritedFlags() command to tell all flags which persisted from a parent

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

authored by Eric Paris · committed by spf13 · parent bf480fe · Browse files · 1 file+28 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+28 added−0 removed

  • other:+28 added−0 removed

1 file+28 added−0 removed

modified:command.go+28 added
735 unmodified lines
736737 return local738}739740// All Flags which were inherited from parents commands741func (c *Command) InheritedFlags() *flag.FlagSet {742 c.mergePersistentFlags()743744 local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)745746 var rmerge func(x *Command)747748 rmerge = func(x *Command) {749 if x.HasPersistentFlags() {750 x.PersistentFlags().VisitAll(func(f *flag.Flag) {751 if local.Lookup(f.Name) == nil {752 local.AddFlag(f)753 }754 })755 }756 if x.HasParent() {757 rmerge(x.parent)758 }759 }760761 if c.HasParent() {762 rmerge(c.parent)763 }764765 return local766}767768// Get the Persistent FlagSet specifically set in the current command769func (c *Command) PersistentFlags() *flag.FlagSet {770 if c.pflags == nil {771 c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
122 unmodified lines