LocalFlags returns the local FlagSet specifically set in the current command. This function does not modify the flags of the current command, it's purpose is to return the current state.
()
| 1714 | // LocalFlags returns the local FlagSet specifically set in the current command. |
| 1715 | // This function does not modify the flags of the current command, it's purpose is to return the current state. |
| 1716 | func (c *Command) LocalFlags() *flag.FlagSet { |
| 1717 | c.mergePersistentFlags() |
| 1718 | |
| 1719 | if c.lflags == nil { |
| 1720 | c.lflags = flag.NewFlagSet(c.DisplayName(), flag.ContinueOnError) |
| 1721 | if c.flagErrorBuf == nil { |
| 1722 | c.flagErrorBuf = new(bytes.Buffer) |
| 1723 | } |
| 1724 | c.lflags.SetOutput(c.flagErrorBuf) |
| 1725 | } |
| 1726 | c.lflags.SortFlags = c.Flags().SortFlags |
| 1727 | if c.globNormFunc != nil { |
| 1728 | c.lflags.SetNormalizeFunc(c.globNormFunc) |
| 1729 | } |
| 1730 | |
| 1731 | addToLocal := func(f *flag.Flag) { |
| 1732 | // Add the flag if it is not a parent PFlag, or it shadows a parent PFlag |
| 1733 | if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) { |
| 1734 | c.lflags.AddFlag(f) |
| 1735 | } |
| 1736 | } |
| 1737 | c.Flags().VisitAll(addToLocal) |
| 1738 | c.PersistentFlags().VisitAll(addToLocal) |
| 1739 | return c.lflags |
| 1740 | } |
| 1741 | |
| 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. |