ParseFlags parses persistent flag tree and local flags.
(args []string)
| 1866 | |
| 1867 | // ParseFlags parses persistent flag tree and local flags. |
| 1868 | func (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. |
| 1892 | func (c *Command) Parent() *Command { |
no test coverage detected