MCPcopy
hub / github.com/spf13/cobra / LocalFlags

Method LocalFlags

command.go:1716–1740  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
1716func (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.

Callers 10

TestNormPassedOnLocalFunction · 0.95
TestSortedFlagsFunction · 0.95
InheritedFlagsMethod · 0.95
NonInheritedFlagsMethod · 0.95
HasLocalFlagsMethod · 0.95
defaultUsageFuncFunction · 0.80

Calls 5

mergePersistentFlagsMethod · 0.95
DisplayNameMethod · 0.95
FlagsMethod · 0.95
PersistentFlagsMethod · 0.95
SetOutputMethod · 0.80

Tested by 4

TestNormPassedOnLocalFunction · 0.76
TestSortedFlagsFunction · 0.76