Updated Branches:
  refs/heads/1.5.1-SNAPSHOT 090a8cf68 -> d61afcc28

ACCUMULO-1587 add 'print to file' for grep


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

Branch: refs/heads/1.5.1-SNAPSHOT
Commit: d61afcc28901c3d1bf34a5940b76f2e140f3f340
Parents: 090a8cf
Author: Mike Drob <md...@mdrob.com>
Authored: Mon Oct 28 10:08:51 2013 -0400
Committer: Mike Drob <md...@mdrob.com>
Committed: Mon Oct 28 10:08:51 2013 -0400

----------------------------------------------------------------------
 .../accumulo/core/util/shell/commands/GrepCommand.java    |  4 +++-
 .../accumulo/core/util/shell/commands/ScanCommand.java    | 10 +++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/d61afcc2/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
 
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
index 828e0d9..c2ff232 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
@@ -27,6 +27,7 @@ import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.util.format.Formatter;
 import org.apache.accumulo.core.util.interpret.ScanInterpreter;
 import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.PrintFile;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.MissingArgumentException;
 import org.apache.commons.cli.Option;
@@ -38,6 +39,7 @@ public class GrepCommand extends ScanCommand {
   
   @Override
   public int execute(final String fullCommand, final CommandLine cl, final 
Shell shellState) throws Exception {
+    final PrintFile printFile = getOutputFile(cl);
     
     final String tableName = OptUtil.getTableOpt(cl, shellState);
     
@@ -67,7 +69,7 @@ public class GrepCommand extends ScanCommand {
       fetchColumns(cl, scanner, interpeter);
       
       // output the records
-      printRecords(cl, shellState, scanner, formatter);
+      printRecords(cl, shellState, scanner, formatter, printFile);
     } finally {
       scanner.close();
     }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/d61afcc2/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
 
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
index 5359ea0..74aa699 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.core.util.shell.commands;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
@@ -58,9 +59,7 @@ public class ScanCommand extends Command {
   private Option profileOpt;
   
   public int execute(final String fullCommand, final CommandLine cl, final 
Shell shellState) throws Exception {
-
-    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
-    final PrintFile printFile = outputFile == null ? null : new 
PrintFile(outputFile);
+    final PrintFile printFile = getOutputFile(cl);
     
     final String tableName = OptUtil.getTableOpt(cl, shellState);
     
@@ -328,4 +327,9 @@ public class ScanCommand extends Command {
   public int numArgs() {
     return 0;
   }
+  
+  protected PrintFile getOutputFile(final CommandLine cl) throws 
FileNotFoundException {
+    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
+    return (outputFile == null ? null : new PrintFile(outputFile));
+  }
 }

Reply via email to