Extract the first column from Clap's `Commands:` section. Command rows have exactly two leading spaces. Wrapped descriptions are indented further, so they are ignored.
(help: &str)
| 35 | /// Command rows have exactly two leading spaces. Wrapped descriptions are |
| 36 | /// indented further, so they are ignored. |
| 37 | fn visible_subcommands(help: &str) -> Vec<String> { |
| 38 | let mut in_commands = false; |
| 39 | let mut commands = Vec::new(); |
| 40 | |
| 41 | for raw_line in help.lines() { |
| 42 | let line = raw_line.trim_end_matches('\r'); |
| 43 | |
| 44 | if line == "Commands:" { |
| 45 | in_commands = true; |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | if !in_commands { |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | if line.is_empty() { |
| 54 | if !commands.is_empty() { |
| 55 | break; |
| 56 | } |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | let Some(row) = line.strip_prefix(" ") else { |
| 61 | break; |
| 62 | }; |
| 63 | |
| 64 | if row.starts_with(char::is_whitespace) { |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | let Some(name) = row.split_whitespace().next() else { |
| 69 | continue; |
| 70 | }; |
| 71 | |
| 72 | // Clap adds this standard dispatcher automatically. Its child paths |
| 73 | // duplicate the commands already traversed from their canonical path. |
| 74 | if name == "help" { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | commands.push(name.to_string()); |
| 79 | } |
| 80 | |
| 81 | commands |
| 82 | } |
| 83 | |
| 84 | #[test] |
| 85 | fn every_public_command_renders_help() { |
no test coverage detected