karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-4511] grep, fixed '--color never' support
Date Tue, 23 Aug 2016 06:58:04 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 20716032d -> ed36a4eac


[KARAF-4511] grep, fixed '--color never' support


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/ed36a4ea
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/ed36a4ea
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/ed36a4ea

Branch: refs/heads/karaf-4.0.x
Commit: ed36a4eacc6071183dfa21d4b5c466fa2f1590ca
Parents: 2071603
Author: Paolo Antinori <pantinor@redhat.com>
Authored: Fri Apr 29 14:40:55 2016 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Tue Aug 23 08:57:55 2016 +0200

----------------------------------------------------------------------
 .../karaf/shell/commands/impl/GrepAction.java   |  5 +++--
 .../karaf/shell/commands/impl/GrepTest.java     | 21 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ed36a4ea/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
index 573714e..0016eda 100644
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
@@ -33,7 +33,6 @@ import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.fusesource.jansi.Ansi;
 
-
 @Command(scope = "shell", name="grep", description="Prints lines matching the given pattern.",
detailedDescription="classpath:grep.txt")
 @Service
 public class GrepAction implements Action {
@@ -141,7 +140,9 @@ public class GrepAction implements Action {
                         nb++;
                     }
                     matcher2.appendTail(sb);
-                    sb.append(Ansi.ansi().reset().toString());
+                    if(color != ColorOption.never) {
+                        sb.append(Ansi.ansi().reset().toString());
+                    }
                     if (!count && lineNumber) {
                         lines.add(String.format("%6d  ", lineno) + sb.toString());
                     } else {

http://git-wip-us.apache.org/repos/asf/karaf/blob/ed36a4ea/shell/commands/src/test/java/org/apache/karaf/shell/commands/impl/GrepTest.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/test/java/org/apache/karaf/shell/commands/impl/GrepTest.java
b/shell/commands/src/test/java/org/apache/karaf/shell/commands/impl/GrepTest.java
index 3845b9d..877b2b8 100644
--- a/shell/commands/src/test/java/org/apache/karaf/shell/commands/impl/GrepTest.java
+++ b/shell/commands/src/test/java/org/apache/karaf/shell/commands/impl/GrepTest.java
@@ -19,7 +19,9 @@
 package org.apache.karaf.shell.commands.impl;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
@@ -41,4 +43,23 @@ public class GrepTest extends TestCase {
             System.setIn(input);
         }
     }
+
+    public void testHonorColorNever() throws Exception {
+        InputStream input = System.in;
+        try {
+            ByteArrayInputStream bais = new ByteArrayInputStream("abc".getBytes());
+            System.setIn(bais);
+            ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+            System.setOut(new PrintStream(outContent));
+
+            GrepAction grep = new GrepAction();
+            DefaultActionPreparator preparator = new DefaultActionPreparator();
+            preparator.prepare(grep, null, Arrays.<Object>asList( "--color", "never",
"b"));
+            grep.execute();
+            assertEquals("abc", outContent.toString().trim());
+        } finally {
+            System.setIn(input);
+            System.setOut(null);
+        }
+    }
 }


Mime
View raw message