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

Method ParseFlags

command.go:1868–1889  ·  view source on GitHub ↗

ParseFlags parses persistent flag tree and local flags.

(args []string)

Source from the content-addressed store, hash-verified

1866
1867// ParseFlags parses persistent flag tree and local flags.
1868func (c *Command) ParseFlags(args []string) error {
1869 if c.DisableFlagParsing {
1870 return nil
1871 }
1872
1873 if c.flagErrorBuf == nil {
1874 c.flagErrorBuf = new(bytes.Buffer)
1875 }
1876 beforeErrorBufLen := c.flagErrorBuf.Len()
1877 c.mergePersistentFlags()
1878
1879 // do it here after merging all flags and just before parse
1880 c.Flags().ParseErrorsAllowlist = flag.ParseErrorsAllowlist(c.FParseErrWhitelist)
1881
1882 err := c.Flags().Parse(args)
1883 // Print warnings if they occurred (e.g. deprecated flag messages).
1884 if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil {
1885 c.Print(c.flagErrorBuf.String())
1886 }
1887
1888 return err
1889}
1890
1891// Parent returns a commands parent command.
1892func (c *Command) Parent() *Command {

Callers 3

getCompletionsMethod · 0.95
TraverseMethod · 0.95
executeMethod · 0.95

Calls 5

mergePersistentFlagsMethod · 0.95
FlagsMethod · 0.95
PrintMethod · 0.95
StringMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected