33//! the upstream crate because it is Clap 4 only. When we move to Clap 4
44//! we should shift to using the original crate (and upstream changes such
55//! as alphabetisation). See licences in this directory and NOTICES.md.
6- //!
6+ //!
77//! Autogenerate Markdown documentation for clap command-line tools
88//!
99//! See [**Examples**][Examples] for examples of the content `clap-markdown`
@@ -79,9 +79,7 @@ pub fn help_markdown<C: clap::CommandFactory>() -> String {
7979}
8080
8181/// Format the help information for `command` as Markdown, with custom options.
82- pub fn help_markdown_custom < C : clap:: CommandFactory > (
83- options : & MarkdownOptions ,
84- ) -> String {
82+ pub fn help_markdown_custom < C : clap:: CommandFactory > ( options : & MarkdownOptions ) -> String {
8583 let command = C :: command ( ) ;
8684
8785 return help_markdown_command_custom ( & command, options) ;
@@ -93,10 +91,7 @@ pub fn help_markdown_command(command: &clap::Command) -> String {
9391}
9492
9593/// Format the help information for `command` as Markdown, with custom options.
96- pub fn help_markdown_command_custom (
97- command : & clap:: Command ,
98- options : & MarkdownOptions ,
99- ) -> String {
94+ pub fn help_markdown_command_custom ( command : & clap:: Command , options : & MarkdownOptions ) -> String {
10095 let mut buffer = String :: with_capacity ( 100 ) ;
10196
10297 write_help_markdown ( & mut buffer, & command, options) ;
@@ -121,11 +116,7 @@ pub fn print_help_markdown<C: clap::CommandFactory>() {
121116 println ! ( "{}" , buffer) ;
122117}
123118
124- fn write_help_markdown (
125- buffer : & mut String ,
126- command : & clap:: Command ,
127- options : & MarkdownOptions ,
128- ) {
119+ fn write_help_markdown ( buffer : & mut String , command : & clap:: Command , options : & MarkdownOptions ) {
129120 //----------------------------------
130121 // Write the document title
131122 //----------------------------------
@@ -142,7 +133,8 @@ fn write_help_markdown(
142133 buffer,
143134 "This document contains the help content for the `{}` command-line program.\n " ,
144135 title_name
145- ) . unwrap ( ) ;
136+ )
137+ . unwrap ( ) ;
146138
147139 //----------------------------------
148140 // Write the table of contents
@@ -155,8 +147,7 @@ fn write_help_markdown(
155147 if options. show_table_of_contents {
156148 writeln ! ( buffer, "**Command Overview:**\n " ) . unwrap ( ) ;
157149
158- build_table_of_contents_markdown ( buffer, Vec :: new ( ) , command, 0 )
159- . unwrap ( ) ;
150+ build_table_of_contents_markdown ( buffer, Vec :: new ( ) , command, 0 ) . unwrap ( ) ;
160151
161152 write ! ( buffer, "\n " ) . unwrap ( ) ;
162153 }
@@ -171,13 +162,17 @@ fn write_help_markdown(
171162 // Write the footer
172163 //-----------------
173164 if options. show_footer {
174- write ! ( buffer, r#"<hr/>
165+ write ! (
166+ buffer,
167+ r#"<hr/>
175168
176169<small><i>
177170 This document was generated automatically by
178171 <a href="https://crates.io/crates/clap-markdown"><code>clap-markdown</code></a>.
179172</i></small>
180- "# ) . unwrap ( ) ;
173+ "#
174+ )
175+ . unwrap ( ) ;
181176 }
182177}
183178
@@ -215,12 +210,7 @@ fn build_table_of_contents_markdown(
215210 //----------------------------------
216211
217212 for subcommand in command. get_subcommands ( ) . sorted_by_key ( |c| c. get_name ( ) ) {
218- build_table_of_contents_markdown (
219- buffer,
220- command_path. clone ( ) ,
221- subcommand,
222- depth + 1 ,
223- ) ?;
213+ build_table_of_contents_markdown ( buffer, command_path. clone ( ) , subcommand, depth + 1 ) ?;
224214 }
225215
226216 Ok ( ( ) )
@@ -418,12 +408,7 @@ fn build_command_markdown(
418408 write ! ( buffer, "\n \n " ) ?;
419409
420410 for subcommand in command. get_subcommands ( ) . sorted_by_key ( |c| c. get_name ( ) ) {
421- build_command_markdown (
422- buffer,
423- command_path. clone ( ) ,
424- subcommand,
425- depth + 1 ,
426- ) ?;
411+ build_command_markdown ( buffer, command_path. clone ( ) , subcommand, depth + 1 ) ?;
427412 }
428413
429414 Ok ( ( ) )
@@ -447,9 +432,7 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
447432 let value_name: String = match arg. get_value_names ( ) {
448433 // TODO: What if multiple names are provided?
449434 Some ( [ name, ..] ) => name. to_string ( ) ,
450- Some ( [ ] ) => unreachable ! (
451- "clap Arg::get_value_names() returned Some(..) of empty list"
452- ) ,
435+ Some ( [ ] ) => unreachable ! ( "clap Arg::get_value_names() returned Some(..) of empty list" ) ,
453436 None => arg. get_id ( ) . to_string ( ) . to_ascii_uppercase ( ) ,
454437 } ;
455438
@@ -460,26 +443,29 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
460443 } else {
461444 write ! ( buffer, "`-{short}`, `--{long}`" ) ?
462445 }
463- } ,
446+ }
464447 ( Some ( short) , None ) => {
465448 if arg. get_action ( ) . takes_values ( ) {
466449 write ! ( buffer, "`-{short} <{value_name}>`" ) ?
467450 } else {
468451 write ! ( buffer, "`-{short}`" ) ?
469452 }
470- } ,
453+ }
471454 ( None , Some ( long) ) => {
472455 if arg. get_action ( ) . takes_values ( ) {
473456 write ! ( buffer, "`--{} <{value_name}>`" , long) ?
474457 } else {
475458 write ! ( buffer, "`--{}`" , long) ?
476459 }
477- } ,
460+ }
478461 ( None , None ) => {
479- debug_assert ! ( arg. is_positional( ) , "unexpected non-positional Arg with neither short nor long name: {arg:?}" ) ;
462+ debug_assert ! (
463+ arg. is_positional( ) ,
464+ "unexpected non-positional Arg with neither short nor long name: {arg:?}"
465+ ) ;
480466
481467 write ! ( buffer, "`<{value_name}>`" , ) ?;
482- } ,
468+ }
483469 }
484470
485471 if let Some ( help) = arg. get_long_help ( ) {
@@ -517,19 +503,17 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
517503 //--------------------
518504
519505 let possible_values = arg
520- . get_possible_values ( )
521- . unwrap_or_default ( )
506+ . get_value_parser ( )
507+ . possible_values ( )
522508 . into_iter ( )
509+ . flatten ( )
523510 . filter ( |pv| !pv. is_hide_set ( ) )
524511 . collect :: < Vec < _ > > ( ) ;
525512
526513 // Print possible values for options that take a value, but not for flags
527514 // that can only be either present or absent and do not take a value.
528- if !possible_values. is_empty ( )
529- && !matches ! ( arg. get_action( ) , clap:: ArgAction :: SetTrue )
530- {
531- let any_have_help: bool =
532- possible_values. iter ( ) . any ( |pv| pv. get_help ( ) . is_some ( ) ) ;
515+ if !possible_values. is_empty ( ) && !matches ! ( arg. get_action( ) , clap:: ArgAction :: SetTrue ) {
516+ let any_have_help: bool = possible_values. iter ( ) . any ( |pv| pv. get_help ( ) . is_some ( ) ) ;
533517
534518 if any_have_help {
535519 // If any of the possible values have help text, print them
@@ -548,7 +532,7 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
548532 . map ( |pv| match pv. get_help ( ) {
549533 Some ( help) => {
550534 format ! ( " - `{}`:\n {}\n " , pv. get_name( ) , help)
551- } ,
535+ }
552536 None => format ! ( " - `{}`\n " , pv. get_name( ) ) ,
553537 } )
554538 . collect :: < Vec < String > > ( )
0 commit comments