mirror of https://github.com/spf13/cobra.git
new NonInheritedFlags() which give all flags which were not persisted from a parent command
This commit is contained in:
parent
b96dd75141
commit
f8e1ec56bd
16
command.go
16
command.go
|
@ -765,6 +765,22 @@ func (c *Command) InheritedFlags() *flag.FlagSet {
|
||||||
return local
|
return local
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All Flags which were not inherited from parent commands
|
||||||
|
func (c *Command) NonInheritedFlags() *flag.FlagSet {
|
||||||
|
c.mergePersistentFlags()
|
||||||
|
|
||||||
|
local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
|
inheritedFlags := c.InheritedFlags()
|
||||||
|
|
||||||
|
c.Flags().VisitAll(func(f *flag.Flag) {
|
||||||
|
if inheritedFlags.Lookup(f.Name) == nil {
|
||||||
|
local.AddFlag(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
|
||||||
// Get the Persistent FlagSet specifically set in the current command
|
// Get the Persistent FlagSet specifically set in the current command
|
||||||
func (c *Command) PersistentFlags() *flag.FlagSet {
|
func (c *Command) PersistentFlags() *flag.FlagSet {
|
||||||
if c.pflags == nil {
|
if c.pflags == nil {
|
||||||
|
|
Loading…
Reference in New Issue