InheritedFlags returns all flags which were inherited from parent commands. This function does not modify the flags of the current command, it's purpose is to return the current state.
()
| 1742 | // InheritedFlags returns all flags which were inherited from parent commands. |
| 1743 | // This function does not modify the flags of the current command, it's purpose is to return the current state. |
| 1744 | func (c *Command) InheritedFlags() *flag.FlagSet { |
| 1745 | c.mergePersistentFlags() |
| 1746 | |
| 1747 | if c.iflags == nil { |
| 1748 | c.iflags = flag.NewFlagSet(c.DisplayName(), flag.ContinueOnError) |
| 1749 | if c.flagErrorBuf == nil { |
| 1750 | c.flagErrorBuf = new(bytes.Buffer) |
| 1751 | } |
| 1752 | c.iflags.SetOutput(c.flagErrorBuf) |
| 1753 | } |
| 1754 | |
| 1755 | local := c.LocalFlags() |
| 1756 | if c.globNormFunc != nil { |
| 1757 | c.iflags.SetNormalizeFunc(c.globNormFunc) |
| 1758 | } |
| 1759 | |
| 1760 | c.parentsPflags.VisitAll(func(f *flag.Flag) { |
| 1761 | if c.iflags.Lookup(f.Name) == nil && local.Lookup(f.Name) == nil { |
| 1762 | c.iflags.AddFlag(f) |
| 1763 | } |
| 1764 | }) |
| 1765 | return c.iflags |
| 1766 | } |
| 1767 | |
| 1768 | // NonInheritedFlags returns all flags which were not inherited from parent commands. |
| 1769 | // This function does not modify the flags of the current command, it's purpose is to return the current state. |