Fixed inverted logic on -S and --chop-long-lines

This commit is contained in:
John Higgins 2022-10-13 23:52:15 -07:00
parent 03216c9c18
commit 236a2c5794
No known key found for this signature in database
GPG Key ID: 192DF5D301BD714C
4 changed files with 18 additions and 38 deletions

View File

@ -1,6 +1,7 @@
# unreleased # unreleased
## Features ## Features
- Implemented `-S` and `--chop-long-lines` flags as aliases for `--wrap=character`. See #2309 (@johnmatthiggins)
## Bugfixes ## Bugfixes

View File

@ -175,7 +175,7 @@ impl App {
_ => unreachable!("other values for --wrap are not allowed"), _ => unreachable!("other values for --wrap are not allowed"),
} }
} else { } else {
WrappingMode::Character WrappingMode::NoWrapping(true)
} }
} else { } else {
// We don't have the tty width when piping to another program. // We don't have the tty width when piping to another program.

View File

@ -206,7 +206,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> {
.long("chop-long-lines") .long("chop-long-lines")
.short('S') .short('S')
.takes_value(false) .takes_value(false)
.help("Truncate all lines longer than screen width. Alias for '--wrap=never'."), .help("Truncate all lines longer than screen width. Alias for '--wrap=character'."),
) )
.arg( .arg(
Arg::new("terminal-width") Arg::new("terminal-width")

View File

@ -1501,17 +1501,12 @@ fn ignored_suffix_arg() {
#[test] #[test]
fn no_line_wrapping_when_set_to_never() { fn no_line_wrapping_when_set_to_never() {
let expected = let expected = "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz
"───────┬────────────────────────────────────────────────────────────────────────
File: 80-columns.txt
Size: 101 B
1 abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz
"; ";
bat() bat()
.arg("--style=full") .arg("--style=rule")
.arg("--color=never")
.arg("--decorations=always") .arg("--decorations=always")
.arg("--wrap=never") .arg("--wrap=never")
.arg("--terminal-width=80") .arg("--terminal-width=80")
@ -1525,17 +1520,13 @@ fn no_line_wrapping_when_set_to_never() {
#[test] #[test]
fn line_wrapping_when_auto() { fn line_wrapping_when_auto() {
let expected = let expected =
"───────┬──────────────────────────────────────────────────────────────────────── "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde
File: 80-columns.txt fghigklmnopqrstuvxyz
Size: 101 B
1 abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu
vxyzabcdefghigklmnopqrstuvxyz
"; ";
bat() bat()
.arg("--style=full") .arg("--color=never")
.arg("--style=rule")
.arg("--decorations=always") .arg("--decorations=always")
.arg("--wrap=auto") .arg("--wrap=auto")
.arg("--terminal-width=80") .arg("--terminal-width=80")
@ -1547,19 +1538,13 @@ fn line_wrapping_when_auto() {
} }
#[test] #[test]
fn line_wrapping_with_s_flag() { fn no_line_wrapping_with_s_flag() {
let expected = let expected =
"───────┬──────────────────────────────────────────────────────────────────────── "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n";
File: 80-columns.txt
Size: 101 B
1 abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu
vxyzabcdefghigklmnopqrstuvxyz
";
bat() bat()
.arg("--style=full") .arg("--color=never")
.arg("--style=rule")
.arg("--decorations=always") .arg("--decorations=always")
.arg("-S") .arg("-S")
.arg("--terminal-width=80") .arg("--terminal-width=80")
@ -1571,19 +1556,13 @@ fn line_wrapping_with_s_flag() {
} }
#[test] #[test]
fn chop_long_lines_when_specified() { fn no_wrapping_with_chop_long_lines() {
let expected = let expected =
"───────┬──────────────────────────────────────────────────────────────────────── "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n";
File: 80-columns.txt
Size: 101 B
1 abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu
vxyzabcdefghigklmnopqrstuvxyz
";
bat() bat()
.arg("--style=full") .arg("--color=never")
.arg("--style=rule")
.arg("--decorations=always") .arg("--decorations=always")
.arg("--chop-long-lines") .arg("--chop-long-lines")
.arg("--terminal-width=80") .arg("--terminal-width=80")