Skip to content

Commit

Permalink
Merge #1810
Browse files Browse the repository at this point in the history
1810: Remove {n} support r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
  • Loading branch information
bors[bot] and pksunkara authored Apr 12, 2020
2 parents 1e6d366 + 333b993 commit 7788268
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/build/usage_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
);
Expand Down
23 changes: 8 additions & 15 deletions src/output/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 7788268

Please sign in to comment.