Skip to content

Commit

Permalink
Add anchor links to arguments and options in the CLI reference
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Feb 24, 2025
1 parent 1f7f9fd commit 08140c7
Show file tree
Hide file tree
Showing 2 changed files with 1,394 additions and 1,390 deletions.
14 changes: 9 additions & 5 deletions crates/uv-dev/src/generate_cli_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ fn generate_command<'a>(output: &mut String, command: &'a Command, parents: &mut

// Do not display options for commands with children
if !has_subcommands {
let name_key = name.replace(' ', "-");

// Display positional arguments
let mut arguments = command
.get_positionals()
Expand All @@ -196,10 +198,11 @@ fn generate_command<'a>(output: &mut String, command: &'a Command, parents: &mut
output.push_str("<dl class=\"cli-reference\">");

for arg in arguments {
output.push_str("<dt>");
let id = format!("{name_key}--{}", arg.get_id());
output.push_str(&format!("<dt id=\"{id}\">"));
output.push_str(&format!(
"<code>{}</code>",
arg.get_id().to_string().to_uppercase()
"<a href=\"#{id}\"<code>{}</code></a>",
arg.get_id().to_string().to_uppercase(),
));
output.push_str("</dt>");
if let Some(help) = arg.get_long_help().or_else(|| arg.get_help()) {
Expand All @@ -225,9 +228,10 @@ fn generate_command<'a>(output: &mut String, command: &'a Command, parents: &mut
output.push_str("<dl class=\"cli-reference\">");
for opt in options {
let Some(long) = opt.get_long() else { continue };
let id = format!("{name_key}--{long}");

output.push_str("<dt>");
output.push_str(&format!("<code>--{long}</code>"));
output.push_str(&format!("<dt id=\"{id}\">"));
output.push_str(&format!("<a href=\"#{id}\"><code>--{long}</code></a>",));
if let Some(short) = opt.get_short() {
output.push_str(&format!(", <code>-{short}</code>"));
}
Expand Down
Loading

0 comments on commit 08140c7

Please sign in to comment.