unknownFlagTokens returns the flag tokens in rawArgs that cmd does not define (on itself, inherited, or any direct subcommand). installUnknownSubcommandGuard whitelists unknown flags on pure groups so a mistyped subcommand still reaches the suggestion path; the side effect is that flags before a sub
(cmd *cobra.Command, rawArgs []string)
| 453 | // swallowed. This recovers the genuinely-unknown ones so the caller can name |
| 454 | // them in a "did you mean" envelope. |
| 455 | func unknownFlagTokens(cmd *cobra.Command, rawArgs []string) []string { |
| 456 | var unknown []string |
| 457 | for _, a := range flagTokensInArgs(rawArgs) { |
| 458 | name := strings.SplitN(strings.TrimLeft(a, "-"), "=", 2)[0] |
| 459 | if name != "" && !flagDefinedInTree(cmd, name) { |
| 460 | unknown = append(unknown, a) |
| 461 | } |
| 462 | } |
| 463 | return unknown |
| 464 | } |
| 465 | |
| 466 | // flagKnownOnGroup reports whether name is a flag defined on cmd itself or |
| 467 | // inherited (a global persistent flag like --profile) — i.e. valid on the bare |