mirror of
https://github.com/spf13/cobra
synced 2024-11-25 07:07:15 +00:00
checking if a flag is 'private' before adding it to the list of flags; this allows for hidden flags
This commit is contained in:
parent
68f5a81a72
commit
0a7cad51ef
1 changed files with 9 additions and 3 deletions
|
@ -917,13 +917,17 @@ func (c *Command) LocalFlags() *flag.FlagSet {
|
||||||
|
|
||||||
local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
c.lflags.VisitAll(func(f *flag.Flag) {
|
c.lflags.VisitAll(func(f *flag.Flag) {
|
||||||
|
if !f.Private {
|
||||||
local.AddFlag(f)
|
local.AddFlag(f)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if !c.HasParent() {
|
if !c.HasParent() {
|
||||||
flag.CommandLine.VisitAll(func(f *flag.Flag) {
|
flag.CommandLine.VisitAll(func(f *flag.Flag) {
|
||||||
if local.Lookup(f.Name) == nil {
|
if local.Lookup(f.Name) == nil {
|
||||||
|
if !f.Private {
|
||||||
local.AddFlag(f)
|
local.AddFlag(f)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return local
|
return local
|
||||||
|
@ -942,8 +946,10 @@ func (c *Command) InheritedFlags() *flag.FlagSet {
|
||||||
if x.HasPersistentFlags() {
|
if x.HasPersistentFlags() {
|
||||||
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
||||||
if inherited.Lookup(f.Name) == nil && local.Lookup(f.Name) == nil {
|
if inherited.Lookup(f.Name) == nil && local.Lookup(f.Name) == nil {
|
||||||
|
if !f.Private {
|
||||||
inherited.AddFlag(f)
|
inherited.AddFlag(f)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if x.HasParent() {
|
if x.HasParent() {
|
||||||
|
|
Loading…
Reference in a new issue