add new flag to lflags

This commit is contained in:
Jun Nishimura 2023-07-19 00:35:39 +09:00
parent dcb405a939
commit 8bff6aff17

View file

@ -1633,7 +1633,10 @@ func (c *Command) LocalFlags() *flag.FlagSet {
addToLocal := func(f *flag.Flag) { addToLocal := func(f *flag.Flag) {
// Add the flag if it is not a parent PFlag, or it shadows a parent PFlag // Add the flag if it is not a parent PFlag, or it shadows a parent PFlag
if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) { if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) {
c.lflags.AddFlag(f) newFlag := &flag.Flag{}
*newFlag = *f
newFlag.Changed = false
c.lflags.AddFlag(newFlag)
} }
} }
c.Flags().VisitAll(addToLocal) c.Flags().VisitAll(addToLocal)