From 0a7cad51ef27200ce065067b0d6401c15f4fb509 Mon Sep 17 00:00:00 2001 From: Steve Domino Date: Fri, 4 Sep 2015 16:29:28 -0600 Subject: [PATCH] checking if a flag is 'private' before adding it to the list of flags; this allows for hidden flags --- command.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index bf642b53..21e001da 100644 --- a/command.go +++ b/command.go @@ -917,12 +917,16 @@ func (c *Command) LocalFlags() *flag.FlagSet { local := flag.NewFlagSet(c.Name(), flag.ContinueOnError) c.lflags.VisitAll(func(f *flag.Flag) { - local.AddFlag(f) + if !f.Private { + local.AddFlag(f) + } }) if !c.HasParent() { flag.CommandLine.VisitAll(func(f *flag.Flag) { if local.Lookup(f.Name) == nil { - local.AddFlag(f) + if !f.Private { + local.AddFlag(f) + } } }) } @@ -942,7 +946,9 @@ func (c *Command) InheritedFlags() *flag.FlagSet { if x.HasPersistentFlags() { x.PersistentFlags().VisitAll(func(f *flag.Flag) { if inherited.Lookup(f.Name) == nil && local.Lookup(f.Name) == nil { - inherited.AddFlag(f) + if !f.Private { + inherited.AddFlag(f) + } } }) }