cosmetic: spec_vals on separate lines for long help

This commit is contained in:
Julius Michaelis 2021-10-17 13:05:35 +09:00
parent 1c2b09e57b
commit 16af4f230a
2 changed files with 27 additions and 2 deletions

View file

@ -184,3 +184,23 @@ fn verbatim_doc_comment_field() {
assert!(help.contains("This help ends in a period."));
assert!(help.contains("This help does not end in a period"));
}
#[test]
fn multiline_separates_default() {
#[derive(Parser, Debug)]
struct App {
/// Multiline
///
/// Doc comment
#[clap(long, default_value = "x")]
x: String,
}
let help = get_long_help::<App>();
assert!(!help.contains("Doc comment [default"));
assert!(help.lines().any(|s| s.trim().starts_with("[default")));
// The short help should still have the default on the same line
let help = get_help::<App>();
assert!(help.contains("Multiline [default"));
}

View file

@ -604,12 +604,17 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
spec_vals.push(format!("[possible values: {}]", pvs));
}
let connector = if self.use_long { "\n" } else { " " };
let prefix = if !spec_vals.is_empty() && !a.get_about().unwrap_or("").is_empty() {
" "
if self.use_long {
"\n\n"
} else {
" "
}
} else {
""
};
prefix.to_string() + &spec_vals.join(" ")
prefix.to_string() + &spec_vals.join(connector)
}
fn write_about(&mut self, before_new_line: bool, after_new_line: bool) -> io::Result<()> {