From ff564ea4f0408fdc49308dce7698b0b85851a792 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Fri, 9 Oct 2026 19:29:29 +0200 Subject: [PATCH] soundcraft-cli --help: stop at the closing code fence, no Rust source lines (#48) --- apps/soundcraft-cli/src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/soundcraft-cli/src/main.rs b/apps/soundcraft-cli/src/main.rs index 9dc8ec3..fb1d856 100644 --- a/apps/soundcraft-cli/src/main.rs +++ b/apps/soundcraft-cli/src/main.rs @@ -37,6 +37,17 @@ fn fail(msg: impl std::fmt::Display) -> ExitCode { ExitCode::FAILURE } +/// The usage block of the module doc comment, up to its closing code fence. +fn help_text() -> String { + include_str!("main.rs") + .lines() + .skip(3) + .take_while(|l| l.trim_end() != "//! ```") + .map(|l| l.trim_start_matches("//! ")) + .collect::>() + .join("\n") +} + fn main() -> ExitCode { let args: Vec = std::env::args().skip(1).collect(); let Some(cmd) = args.first().cloned() else { @@ -50,7 +61,7 @@ fn main() -> ExitCode { ExitCode::SUCCESS } "--help" | "-h" | "help" => { - outln!("{}", include_str!("main.rs").lines().skip(3).take(14).map(|l| l.trim_start_matches("//! ")).collect::>().join("\n")); + outln!("{}", help_text()); ExitCode::SUCCESS } "info" => info(&rest), @@ -336,3 +347,17 @@ fn parity(args: &[String]) -> ExitCode { } ExitCode::SUCCESS } + +#[cfg(test)] +mod tests { + use super::help_text; + + #[test] + fn help_text_is_only_the_usage_block() { + let help = help_text(); + assert!(help.starts_with("soundcraft-cli info FILE")); + assert!(help.ends_with("soundcraft-cli plugins list built-in plugins")); + assert!(!help.contains("```")); + assert!(!help.contains("#![") && !help.contains("use serde_json")); + } +}