The command path clap itself scoped the error to, read out of its usage line. This is the authoritative source when it exists. argv alone cannot answer the question: in `atomic --json memory new`, clap rejects `--json` at the ROOT and never reaches `memory`, yet `memory` and `new` are both real subcommands sitting later in argv. Walking argv names `memory new` — a command that never ran — and the
(root: &clap::Command, usage: &str)
| 63 | /// <COMMAND>`; the path is its leading run of bare lowercase tokens after the |
| 64 | /// binary name. |
| 65 | fn path_from_usage(root: &clap::Command, usage: &str) -> Option<String> { |
| 66 | let mut toks = usage.split_whitespace(); |
| 67 | if toks.next()? != root.get_name() { |
| 68 | return None; |
| 69 | } |
| 70 | let mut node = root; |
| 71 | let mut parts: Vec<String> = Vec::new(); |
| 72 | for tok in toks { |
| 73 | if !tok |
| 74 | .chars() |
| 75 | .all(|c| c.is_ascii_lowercase() || c == '-' || c.is_ascii_digit()) |
| 76 | || tok.starts_with('-') |
| 77 | { |
| 78 | break; |
| 79 | } |
| 80 | match node.find_subcommand(tok) { |
| 81 | Some(child) => { |
| 82 | parts.push(child.get_name().to_string()); |
| 83 | node = child; |
| 84 | } |
| 85 | None => break, |
| 86 | } |
| 87 | } |
| 88 | Some(parts.join(" ")) |
| 89 | } |
| 90 | |
| 91 | /// Walk argv against the live command tree to the deepest node that actually |
| 92 | /// exists. |