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

Function visible_subcommands

atomic-cli/tests/cli_surface_integration_test.rs:39–90  ·  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. Rows marked `[REMOVED` are skipped: those are deprecation shims that deliberately print a redirect and exit non-zero instead of rendering help, so they are not public commands.

(help: &str)

Source from the content-addressed store, hash-verified

37/// those are deprecation shims that deliberately print a redirect and exit
38/// non-zero instead of rendering help, so they are not public commands.
39fn visible_subcommands(help: &str) -> Vec<String> {
40 let mut in_commands = false;
41 let mut commands = Vec::new();
42
43 for raw_line in help.lines() {
44 let line = raw_line.trim_end_matches('\r');
45
46 if line == "Commands:" {
47 in_commands = true;
48 continue;
49 }
50
51 if !in_commands {
52 continue;
53 }
54
55 if line.is_empty() {
56 if !commands.is_empty() {
57 break;
58 }
59 continue;
60 }
61
62 let Some(row) = line.strip_prefix(" ") else {
63 break;
64 };
65
66 if row.starts_with(char::is_whitespace) {
67 continue;
68 }
69
70 let Some(name) = row.split_whitespace().next() else {
71 continue;
72 };
73
74 // Clap adds this standard dispatcher automatically. Its child paths
75 // duplicate the commands already traversed from their canonical path.
76 if name == "help" {
77 continue;
78 }
79
80 // Retired command families keep a shim that redirects to the new path
81 // and exits non-zero; it has no help to render.
82 if row.contains("[REMOVED") {
83 continue;
84 }
85
86 commands.push(name.to_string());
87 }
88
89 commands
90}
91
92#[test]
93fn every_public_command_renders_help() {

Callers 1

Calls 5

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

Tested by

no test coverage detected