MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / visible_subcommands

Function visible_subcommands

atomic-cli/tests/cli_surface_integration_test.rs:37–82  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

35/// Command rows have exactly two leading spaces. Wrapped descriptions are
36/// indented further, so they are ignored.
37fn 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]
85fn every_public_command_renders_help() {

Callers 1

Calls 4

linesMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected