flagDefinedInTree reports whether name is defined on cmd, its inherited (persistent) flags, or any direct subcommand. The subcommand case covers a user who merely omitted the subcommand — e.g. `sheets --format json`, where --format is injected on every leaf shortcut, not on the group — so only a gen
(cmd *cobra.Command, name string)
| 502 | // --format is injected on every leaf shortcut, not on the group — so only a |
| 503 | // genuinely unknown flag like `sheets --badflag` is reported. |
| 504 | func flagDefinedInTree(cmd *cobra.Command, name string) bool { |
| 505 | short := len(name) == 1 |
| 506 | known := func(c *cobra.Command, inherited bool) bool { |
| 507 | fs := c.Flags() |
| 508 | if inherited { |
| 509 | fs = c.InheritedFlags() |
| 510 | } |
| 511 | if short { |
| 512 | return fs.ShorthandLookup(name) != nil |
| 513 | } |
| 514 | return fs.Lookup(name) != nil |
| 515 | } |
| 516 | if known(cmd, false) || known(cmd, true) { |
| 517 | return true |
| 518 | } |
| 519 | for _, c := range cmd.Commands() { |
| 520 | if known(c, false) { |
| 521 | return true |
| 522 | } |
| 523 | } |
| 524 | return false |
| 525 | } |
| 526 | |
| 527 | // availableSubcommandNames returns the invokable subcommand names of cmd, split |
| 528 | // into current commands and backward-compatibility aliases (those tagged into |
no test coverage detected