mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
cosmetic: spec_vals on separate lines for long help
This commit is contained in:
parent
1c2b09e57b
commit
16af4f230a
2 changed files with 27 additions and 2 deletions
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
Loading…
Reference in a new issue