Skip to content

Commit c4b5c02

Browse files
CopilotKSXGitHub
andcommitted
refactor(usage_md): address all review comments and fix CI failures
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
1 parent 9632a78 commit c4b5c02

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/usage_md.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub fn render_usage_md() -> String {
2020
let usage_str = command.render_usage().to_string();
2121
let usage_cmd = usage_str
2222
.trim()
23-
.splitn(2, ':')
24-
.nth(1)
25-
.map(str::trim)
23+
.split_once(':')
24+
.map(|(_, rest)| rest.trim())
2625
.unwrap_or("");
2726
out.push_str("# Usage\n\n```sh\n");
2827
out.push_str(usage_cmd);
@@ -217,11 +216,12 @@ fn render_examples_section<'a>(lines: impl Iterator<Item = &'a str>, out: &mut S
217216
continue;
218217
}
219218
if let Some(cmd) = trimmed.strip_prefix('$').map(str::trim) {
220-
if let Some(title) = current_title.take() {
221-
out.push_str(&format!("### {title}\n\n```sh\n{cmd}\n```\n\n"));
219+
let heading = if let Some(title) = current_title.take() {
220+
title.to_string()
222221
} else {
223-
out.push_str(&format!("### `{cmd}`\n\n```sh\n{cmd}\n```\n\n"));
224-
}
222+
format!("`{cmd}`")
223+
};
224+
out.push_str(&format!("### {heading}\n\n```sh\n{cmd}\n```\n\n"));
225225
} else {
226226
current_title = Some(trimmed);
227227
}

0 commit comments

Comments
 (0)