From bf34c0406040f7a60050e3055ecb8c1ffc2420e6 Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Tue, 11 Aug 2020 14:46:09 -0700 Subject: [PATCH 1/3] Add a test for --help with long argument help. --- tests/help.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/help.rs b/tests/help.rs index d4e9d63c..67781775 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -354,6 +354,24 @@ FLAGS: Prints version information"; +// FIXME: #1642 This should have an empty line before `-h, --help`. +static ISSUE_1642: &str = "prog + +USAGE: + prog [FLAGS] + +FLAGS: + --config + The config file used by the myprog must be in JSON format + with only valid keys and may not contain other nonsense + that cannot be read by this program. Obviously I'm going on + and on, so I'll stop now. + -h, --help + Prints help information + + -V, --version + Prints version information"; + static CUSTOM_VERSION_AND_HELP: &str = "customize 0.1 Nobody You can customize the version and help text @@ -1766,3 +1784,14 @@ fn help_required_and_no_args() { .setting(AppSettings::HelpRequired) .get_matches(); } + +#[test] +fn issue_1642_long_help_spacing() { + let app = App::new("prog").arg(Arg::new("cfg").long("config").long_about( + "The config file used by the myprog must be in JSON format +with only valid keys and may not contain other nonsense +that cannot be read by this program. Obviously I'm going on +and on, so I'll stop now.", + )); + assert!(utils::compare_output(app, "prog --help", ISSUE_1642, false)); +} From f7e2fbf1502e36a95cb0e2125fcec7123e998baf Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Tue, 11 Aug 2020 15:20:34 -0700 Subject: [PATCH 2/3] Print an empty line after multi-line argument help. Fixes #1642. --- src/output/help.rs | 2 +- tests/help.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/output/help.rs b/src/output/help.rs index d378dfde..53a030f7 100644 --- a/src/output/help.rs +++ b/src/output/help.rs @@ -454,7 +454,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> { } self.none(part)?; } - if !prevent_nlh && !help.contains('\n') && (nlh || self.force_next_line) { + if !prevent_nlh && (nlh || self.force_next_line) { self.none("\n")?; } Ok(()) diff --git a/tests/help.rs b/tests/help.rs index 67781775..68d9a1bc 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -269,6 +269,7 @@ FLAGS: -h, --help Prints help information + -V, --version Prints version @@ -354,7 +355,6 @@ FLAGS: Prints version information"; -// FIXME: #1642 This should have an empty line before `-h, --help`. static ISSUE_1642: &str = "prog USAGE: @@ -366,6 +366,7 @@ FLAGS: with only valid keys and may not contain other nonsense that cannot be read by this program. Obviously I'm going on and on, so I'll stop now. + -h, --help Prints help information From 0d8ebeb36b4e631bb09dde835d98daf6a1175a40 Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Tue, 11 Aug 2020 15:27:10 -0700 Subject: [PATCH 3/3] Fix doc comment for Arg::long_about. --- src/build/arg/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index 828487da..2e27bea8 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -599,24 +599,24 @@ impl<'help> Arg<'help> { /// The above example displays /// /// ```text - /// helptest + /// prog /// /// USAGE: - /// helptest [FLAGS] + /// prog [FLAGS] /// /// FLAGS: - /// --config - /// The config file used by the myprog must be in JSON format - /// with only valid keys and may not contain other nonsense - /// that cannot be read by this program. Obviously I'm going on - /// and on, so I'll stop now. + /// --config + /// The config file used by the myprog must be in JSON format + /// with only valid keys and may not contain other nonsense + /// that cannot be read by this program. Obviously I'm going on + /// and on, so I'll stop now. /// - /// -h, --help - /// Prints help information - /// - /// -V, --version - /// Prints version information + /// -h, --help + /// Prints help information /// + /// -V, --version + /// Prints version information + /// ``` /// [`Arg::about`]: ./struct.Arg.html#method.about #[inline] pub fn long_about(mut self, h: &'help str) -> Self {