From 00af0439307dbb13e77c63685a911f834faee93e Mon Sep 17 00:00:00 2001 From: Vincent Ging Ho Yim Date: Sat, 10 May 2025 22:24:56 +1000 Subject: [PATCH 1/4] style: Remove needless `return`s --- src/lib.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 207cd95..e407af2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,46 +38,42 @@ pub struct MarkdownOptions { impl MarkdownOptions { /// Construct a default instance of `MarkdownOptions`. pub fn new() -> Self { - return Self { + Self { title: None, show_footer: true, show_table_of_contents: true, show_aliases: true, - }; + } } /// Set a custom title to use in the generated document. pub fn title(mut self, title: String) -> Self { self.title = Some(title); - - return self; + self } /// Whether to show the default footer advertising `clap-markdown`. pub fn show_footer(mut self, show: bool) -> Self { self.show_footer = show; - - return self; + self } /// Whether to show the default table of contents. pub fn show_table_of_contents(mut self, show: bool) -> Self { self.show_table_of_contents = show; - - return self; + self } /// Whether to show aliases for arguments and commands. pub fn show_aliases(mut self, show: bool) -> Self { self.show_aliases = show; - - return self; + self } } impl Default for MarkdownOptions { fn default() -> Self { - return Self::new(); + Self::new() } } @@ -88,7 +84,6 @@ impl Default for MarkdownOptions { /// Format the help information for `command` as Markdown. pub fn help_markdown() -> String { let command = C::command(); - help_markdown_command(&command) } @@ -97,13 +92,12 @@ pub fn help_markdown_custom( options: &MarkdownOptions, ) -> String { let command = C::command(); - - return help_markdown_command_custom(&command, options); + help_markdown_command_custom(&command, options) } /// Format the help information for `command` as Markdown. pub fn help_markdown_command(command: &clap::Command) -> String { - return help_markdown_command_custom(command, &Default::default()); + help_markdown_command_custom(command, &Default::default()) } /// Format the help information for `command` as Markdown, with custom options. From 5fa9e83cb1987cb35fb894906c0cd34451d6c90b Mon Sep 17 00:00:00 2001 From: Vincent Ging Ho Yim Date: Sat, 10 May 2025 22:32:06 +1000 Subject: [PATCH 2/4] style: Remove needless borrow --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e407af2..1ed2dfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,7 +107,7 @@ pub fn help_markdown_command_custom( ) -> String { let mut buffer = String::with_capacity(100); - write_help_markdown(&mut buffer, &command, options); + write_help_markdown(&mut buffer, command, options); buffer } From 0e80b0cc4b0ffbfda679a3b219c18b33bb731fa5 Mon Sep 17 00:00:00 2001 From: Vincent Ging Ho Yim Date: Mon, 12 May 2025 11:46:00 +1000 Subject: [PATCH 3/4] style: Inline format arguments into format string --- src/lib.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ed2dfd..736b780 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,7 +126,7 @@ pub fn print_help_markdown() { write_help_markdown(&mut buffer, &command, &Default::default()); - println!("{}", buffer); + println!("{buffer}"); } fn write_help_markdown( @@ -148,8 +148,7 @@ fn write_help_markdown( writeln!( buffer, - "This document contains the help content for the `{}` command-line program.\n", - title_name + "This document contains the help content for the `{title_name}` command-line program.\n" ).unwrap(); //---------------------------------- @@ -318,15 +317,15 @@ fn build_command_markdown( writeln!(buffer, "## `{}`\n", command_path.join(" "))?; if let Some(long_about) = command.get_long_about() { - writeln!(buffer, "{}\n", long_about)?; + writeln!(buffer, "{long_about}\n")?; } else if let Some(about) = command.get_about() { - writeln!(buffer, "{}\n", about)?; + writeln!(buffer, "{about}\n")?; } if let Some(help) = command.get_before_long_help() { - writeln!(buffer, "{}\n", help)?; + writeln!(buffer, "{help}\n")?; } else if let Some(help) = command.get_before_help() { - writeln!(buffer, "{}\n", help)?; + writeln!(buffer, "{help}\n")?; } writeln!( @@ -358,9 +357,9 @@ fn build_command_markdown( } if let Some(help) = command.get_after_long_help() { - writeln!(buffer, "{}\n", help)?; + writeln!(buffer, "{help}\n")?; } else if let Some(help) = command.get_after_help() { - writeln!(buffer, "{}\n", help)?; + writeln!(buffer, "{help}\n")?; } //---------------------------------- @@ -472,9 +471,9 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result { }, (None, Some(long)) => { if arg.get_action().takes_values() { - write!(buffer, "`--{} <{value_name}>`", long)? + write!(buffer, "`--{long} <{value_name}>`")? } else { - write!(buffer, "`--{}`", long)? + write!(buffer, "`--{long}`")? } }, (None, None) => { From 29abe6a517bc5ad673e7450fcc61187afda31d62 Mon Sep 17 00:00:00 2001 From: Vincent Ging Ho Yim Date: Mon, 12 May 2025 16:36:09 +1000 Subject: [PATCH 4/4] style: Standardise on `std::fmt::Result` import --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 736b780..9cce1a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ mod test_readme { mod utils; -use std::fmt::{self, Write}; +use std::fmt::Write; use clap::builder::PossibleValue; @@ -441,7 +441,10 @@ fn build_command_markdown( Ok(()) } -fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result { +fn write_arg_markdown( + buffer: &mut String, + arg: &clap::Arg, +) -> std::fmt::Result { // Markdown list item write!(buffer, "* ")?;