subcommandOnlyFlagTokens returns the flag tokens in rawArgs that are valid on a subcommand of cmd but not on cmd itself/inherited — flags supplied while omitting the subcommand they belong to (`im --format json`). Global flags valid on the bare group (e.g. --profile) are excluded so `lark-cli --prof
(cmd *cobra.Command, rawArgs []string)
| 483 | // valid on the bare group (e.g. --profile) are excluded so |
| 484 | // `lark-cli --profile p im` still prints help rather than erroring. |
| 485 | func subcommandOnlyFlagTokens(cmd *cobra.Command, rawArgs []string) []string { |
| 486 | var misplaced []string |
| 487 | for _, a := range flagTokensInArgs(rawArgs) { |
| 488 | name := strings.SplitN(strings.TrimLeft(a, "-"), "=", 2)[0] |
| 489 | if name == "" || flagKnownOnGroup(cmd, name) { |
| 490 | continue |
| 491 | } |
| 492 | if flagDefinedInTree(cmd, name) { |
| 493 | misplaced = append(misplaced, a) |
| 494 | } |
| 495 | } |
| 496 | return misplaced |
| 497 | } |
| 498 | |
| 499 | // flagDefinedInTree reports whether name is defined on cmd, its inherited |
| 500 | // (persistent) flags, or any direct subcommand. The subcommand case covers a |
no test coverage detected