From b75526bd7f92529c8e49c9795d3c0e6bc4143721 Mon Sep 17 00:00:00 2001
From: Andrew Gallant <jamslam@gmail.com>
Date: Mon, 23 Apr 2018 19:25:55 -0400
Subject: [PATCH] output: add --no-column flag

This disables columns in the output if they were otherwise enabled.

Fixes #880
---
 src/app.rs     | 10 +++++++++-
 src/args.rs    |  3 +++
 tests/tests.rs | 28 ++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/app.rs b/src/app.rs
index a0b4eaf6..2c3bfe43 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -741,9 +741,17 @@ fn flag_column(args: &mut Vec<RGArg>) {
 Show column numbers (1-based). This only shows the column numbers for the first
 match on each line. This does not try to account for Unicode. One byte is equal
 to one column. This implies --line-number.
+
+This flag can be disabled with --no-column.
 ");
     let arg = RGArg::switch("column")
-        .help(SHORT).long_help(LONG);
+        .help(SHORT).long_help(LONG)
+        .overrides("no-column");
+    args.push(arg);
+
+    let arg = RGArg::switch("no-column")
+        .hidden()
+        .overrides("column");
     args.push(arg);
 }
 
diff --git a/src/args.rs b/src/args.rs
index 96abec27..516a4d04 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -689,6 +689,9 @@ impl<'a> ArgMatches<'a> {
 
     /// Returns true if and only if column numbers should be shown.
     fn column(&self) -> bool {
+        if self.is_present("no-column") {
+            return false;
+        }
         self.is_present("column") || self.is_present("vimgrep")
     }
 
diff --git a/tests/tests.rs b/tests/tests.rs
index cab1f42d..c9fa002f 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -836,6 +836,34 @@ sherlock:5:12:but Doctor Watson has to have it taken out for him and dusted,
     assert_eq!(lines, expected);
 });
 
+sherlock!(vimgrep_no_line, "Sherlock|Watson", ".",
+|wd: WorkDir, mut cmd: Command| {
+    cmd.arg("--vimgrep").arg("-N");
+
+    let lines: String = wd.stdout(&mut cmd);
+    let expected = "\
+sherlock:16:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:57:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:49:be, to a very large extent, the result of luck. Sherlock Holmes
+sherlock:12:but Doctor Watson has to have it taken out for him and dusted,
+";
+    assert_eq!(lines, expected);
+});
+
+sherlock!(vimgrep_no_line_no_column, "Sherlock|Watson", ".",
+|wd: WorkDir, mut cmd: Command| {
+    cmd.arg("--vimgrep").arg("-N").arg("--no-column");
+
+    let lines: String = wd.stdout(&mut cmd);
+    let expected = "\
+sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:be, to a very large extent, the result of luck. Sherlock Holmes
+sherlock:but Doctor Watson has to have it taken out for him and dusted,
+";
+    assert_eq!(lines, expected);
+});
+
 // See: https://github.com/BurntSushi/ripgrep/issues/16
 clean!(regression_16, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
     wd.create(".gitignore", "ghi/");