summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-Kappes <87168492+J-Kappes@users.noreply.github.com>2023-09-14 03:45:46 +0000
committerGitHub <noreply@github.com>2023-09-14 05:45:46 +0200
commite2bf85e749d87459e3fced697af5cd9cc96eeb8c (patch)
treeef933d84d4087031b7bec05986ec6041bcfa8263
parentfe73010a5ed57d423e46469ee184ba74193bb727 (diff)
Make -pp override --paging and vice versa when passed as a later argument. (#2660)
-rw-r--r--src/bin/bat/clap_app.rs2
-rw-r--r--tests/integration_tests.rs36
2 files changed, 38 insertions, 0 deletions
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index 01f9d754..8ffeb5b2 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -79,6 +79,7 @@ pub fn build_app(interactive_output: bool) -> Command {
Arg::new("plain")
.overrides_with("plain")
.overrides_with("number")
+ .overrides_with("paging")
.short('p')
.long("plain")
.action(ArgAction::Count)
@@ -303,6 +304,7 @@ pub fn build_app(interactive_output: bool) -> Command {
.long("paging")
.overrides_with("paging")
.overrides_with("no-paging")
+ .overrides_with("plain")
.value_name("when")
.value_parser(["auto", "never", "always"])
.default_value("auto")
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index b118c38f..aa5ca845 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -874,6 +874,42 @@ fn disable_pager_if_disable_paging_flag_comes_after_paging() {
}
#[test]
+fn disable_pager_if_pp_flag_comes_after_paging() {
+ bat()
+ .env("PAGER", "echo pager-output")
+ .arg("--paging=always")
+ .arg("-pp")
+ .arg("test.txt")
+ .assert()
+ .success()
+ .stdout(predicate::eq("hello world\n").normalize());
+}
+
+#[test]
+fn enable_pager_if_disable_paging_flag_comes_before_paging() {
+ bat()
+ .env("PAGER", "echo pager-output")
+ .arg("-P")
+ .arg("--paging=always")
+ .arg("test.txt")
+ .assert()
+ .success()
+ .stdout(predicate::eq("pager-output\n").normalize());
+}
+
+#[test]
+fn enable_pager_if_pp_flag_comes_before_paging() {
+ bat()
+ .env("PAGER", "echo pager-output")
+ .arg("-pp")
+ .arg("--paging=always")
+ .arg("test.txt")
+ .assert()
+ .success()
+ .stdout(predicate::eq("pager-output\n").normalize());
+}
+
+#[test]
fn pager_failed_to_parse() {
bat()
.env("BAT_PAGER", "mismatched-quotes 'a")