From 333b993481396d84197bd6e5b54c526a3b04e6a1 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Sun, 12 Apr 2020 03:36:20 +0200 Subject: [PATCH] Remove {n} support --- .azure-pipelines.yml | 2 ++ .travis.yml | 1 + src/build/usage_parser.rs | 8 ++++---- src/output/help.rs | 23 ++++++++--------------- tests/help.rs | 8 ++++---- tests/utils.rs | 8 +++++++- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index d26b73d2..08587e2e 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -43,6 +43,8 @@ stages: displayName: Cache cargo - script: rustup default $(rust)-$(target) displayName: Install rust + - script: cargo test --no-default-features --features "std cargo" -p clap:3.0.0-beta.1 + displayName: Test with almost no features - script: cargo test --features "yaml unstable" displayName: Test with most features - script: | diff --git a/.travis.yml b/.travis.yml index 90c5baa3..8e74704f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,6 +58,7 @@ jobs: script: - cargo tarpaulin --workspace --features "yaml unstable" --ciserver travis-ci --coveralls $TRAVIS_JOB_ID --timeout 300 script: + - cargo test --no-default-features --features "std cargo" -p clap:3.0.0-beta.1 - cargo test --features "yaml unstable" notifications: email: false diff --git a/src/build/usage_parser.rs b/src/build/usage_parser.rs index ce95d9a9..7992b3c8 100644 --- a/src/build/usage_parser.rs +++ b/src/build/usage_parser.rs @@ -1291,11 +1291,11 @@ mod test { #[test] fn pos_help_newline() { let a = Arg::from( - "[pos]... 'some help{n}\ + "[pos]... 'some help\n\ info'", ); assert_eq!(a.name, "pos"); - assert_eq!(a.help.unwrap(), "some help{n}info"); + assert_eq!(a.help.unwrap(), "some help\ninfo"); assert!( a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences) ); @@ -1307,11 +1307,11 @@ mod test { #[test] fn pos_help_newline_lit_sq() { let a = Arg::from( - "[pos]... 'some help\' stuff{n}\ + "[pos]... 'some help\' stuff\n\ info'", ); assert_eq!(a.name, "pos"); - assert_eq!(a.help.unwrap(), "some help' stuff{n}info"); + assert_eq!(a.help.unwrap(), "some help' stuff\ninfo"); assert!( a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences) ); diff --git a/src/output/help.rs b/src/output/help.rs index 7147447d..0e6efd62 100644 --- a/src/output/help.rs +++ b/src/output/help.rs @@ -359,7 +359,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { let too_long = str_width(h) >= self.term_w; debug!("Help::write_before_after_help: Too long..."); - if too_long || h.contains("{n}") { + if too_long { sdebugln!("Yes"); debugln!("Help::write_before_after_help: help: {}", help); debugln!( @@ -371,7 +371,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { "Help::write_before_after_help: Usable space: {}", self.term_w ); - help = wrap_help(&help.replace("{n}", "\n"), self.term_w); + help = wrap_help(&help, self.term_w); } else { sdebugln!("No"); } @@ -405,14 +405,14 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { } debug!("Help::help: Too long..."); - if too_long && spcs <= self.term_w || h.contains("{n}") { + if too_long && spcs <= self.term_w { sdebugln!("Yes"); debugln!("Help::help: help...{}", help); debugln!("Help::help: help width...{}", str_width(&*help)); // Determine how many newlines we need to insert let avail_chars = self.term_w - spcs; debugln!("Help::help: Usable space...{}", avail_chars); - help = wrap_help(&help.replace("{n}", "\n"), avail_chars); + help = wrap_help(&help, avail_chars); } else { sdebugln!("No"); } @@ -601,14 +601,14 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { } debug!("Help::sc_help: Too long..."); - if too_long && spcs <= self.term_w || h.contains("{n}") { + if too_long && spcs <= self.term_w { sdebugln!("Yes"); debugln!("Help::sc_help: help...{}", help); debugln!("Help::sc_help: help width...{}", str_width(&*help)); // Determine how many newlines we need to insert let avail_chars = self.term_w - spcs; debugln!("Help::sc_help: Usable space...{}", avail_chars); - help = wrap_help(&help.replace("{n}", "\n"), avail_chars); + help = wrap_help(&help, avail_chars); } else { sdebugln!("No"); } @@ -784,10 +784,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { let term_w = self.term_w; macro_rules! write_name { () => {{ - self.color(Format::Good(&*wrap_help( - &self.parser.app.name.replace("{n}", "\n"), - term_w, - )))?; + self.color(Format::Good(&*wrap_help(&self.parser.app.name, term_w)))?; }}; } if let Some(bn) = self.parser.app.bin_name.as_ref() { @@ -813,11 +810,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> { macro_rules! write_thing { ($thing:expr) => {{ - write!( - self.writer, - "{}\n", - wrap_help(&$thing.replace("{n}", "\n"), self.term_w) - )? + write!(self.writer, "{}\n", wrap_help(&$thing, self.term_w))? }}; } // Print the version diff --git a/tests/help.rs b/tests/help.rs index 16985e0a..4e54d80d 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -876,9 +876,9 @@ fn wrapping_newline_chars() { .version("0.1") .set_term_width(60) .arg(Arg::with_name("mode").help( - "x, max, maximum 20 characters, contains symbols.{n}\ - l, long Copy-friendly, 14 characters, contains symbols.{n}\ - m, med, medium Copy-friendly, 8 characters, contains symbols.{n}", + "x, max, maximum 20 characters, contains symbols.\n\ + l, long Copy-friendly, 14 characters, contains symbols.\n\ + m, med, medium Copy-friendly, 8 characters, contains symbols.\n", )); assert!(utils::compare_output( app, @@ -893,7 +893,7 @@ fn old_newline_chars() { let app = App::new("ctest").version("0.1").arg( Arg::with_name("mode") .short('m') - .help("Some help with some wrapping{n}(Defaults to something)"), + .help("Some help with some wrapping\n(Defaults to something)"), ); assert!(utils::compare_output( app, diff --git a/tests/utils.rs b/tests/utils.rs index 295da222..4c2921de 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -54,7 +54,13 @@ pub fn compare_output2(l: App, args: &str, right1: &str, right2: &str, stderr: b err.write_to(&mut buf).unwrap(); let content = buf.into_inner(); let left = String::from_utf8(content).unwrap(); - assert_eq!(stderr, err.use_stderr()); + assert_eq!( + stderr, + err.use_stderr(), + "Should Use STDERR failed. Should be {} but is {}", + stderr, + err.use_stderr() + ); compare(&*left, right1) || compare(&*left, right2) }