incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [4/4] git commit: Made some more shell improvements.
Date Wed, 12 Jun 2013 12:27:00 GMT
Made some more shell improvements.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/1bf69537
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/1bf69537
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/1bf69537

Branch: refs/heads/master
Commit: 1bf69537c734d8868da1379fe055d8332ee358e2
Parents: e6cf18d
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Jun 11 21:24:44 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Jun 11 21:24:44 2013 -0400

----------------------------------------------------------------------
 .../java/org/apache/blur/shell/Command.java     | 19 +++++-
 .../org/apache/blur/shell/GetRowCommand.java    | 62 +++++++++++++++++++-
 .../main/java/org/apache/blur/shell/Main.java   | 10 +++-
 3 files changed, 86 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1bf69537/blur-shell/src/main/java/org/apache/blur/shell/Command.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Command.java b/blur-shell/src/main/java/org/apache/blur/shell/Command.java
index a12883f..11fe713 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Command.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Command.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
@@ -31,7 +33,20 @@ public abstract class Command {
       super(msg);
     }
   }
-  abstract public void doit(PrintWriter out, Blur.Iface client, String[] args)
-      throws CommandException, TException, BlurException;
+
+  private ConsoleReader consoleReader;
+
+  abstract public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException;
+
   abstract public String help();
+
+  public ConsoleReader getConsoleReader() {
+    return consoleReader;
+  }
+
+  public void setConsoleReader(ConsoleReader consoleReader) {
+    this.consoleReader = consoleReader;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1bf69537/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
index 213b7c4..eab34a0 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
@@ -19,18 +19,26 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.List;
+
+import jline.Terminal;
+import jline.console.ConsoleReader;
 
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Column;
 import org.apache.blur.thrift.generated.FetchResult;
 import org.apache.blur.thrift.generated.FetchRowResult;
+import org.apache.blur.thrift.generated.Record;
 import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.thrift.generated.Selector;
 
 public class GetRowCommand extends Command {
+
   @Override
-  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
     if (args.length != 3) {
       throw new CommandException("Invalid args: " + help());
     }
@@ -50,7 +58,57 @@ public class GetRowCommand extends Command {
       out.println("Row [" + rowId + "] not found.");
       return;
     }
-    out.println(row);
+    int maxWidth = 100;
+    ConsoleReader reader = getConsoleReader();
+    if (reader != null) {
+      Terminal terminal = reader.getTerminal();
+      maxWidth = terminal.getWidth() - 15;
+    }
+    format(out, row, maxWidth);
+  }
+
+  private void format(PrintWriter out, Row row, int maxWidth) {
+    String id = row.getId();
+    int recordCount = row.getRecordCount();
+    out.println("id:" + id);
+    out.println("recordCount:" + recordCount);
+    List<Record> records = row.getRecords();
+    for (Record record : records) {
+      format(out, record, maxWidth);
+    }
+  }
+
+  private void format(PrintWriter out, Record record, int maxWidth) {
+    String recordId = record.getRecordId();
+    String family = record.getFamily();
+    List<Column> columns = record.getColumns();
+    out.println(" recordId:" + recordId);
+    out.println("   family:" + family);
+    for (Column column : columns) {
+      format(out, column, maxWidth);
+    }
+  }
+
+  private void format(PrintWriter out, Column column, int maxWidth) {
+    String lead = "     " + column.getName() + ":";
+    String value = column.getValue();
+    int length = value.length();
+    int position = 0;
+    while (length > 0) {
+      int len = Math.min(maxWidth, length);
+      String s = value.substring(position, position + len);
+      if (position == 0) {
+        out.println(lead + s);
+      } else {
+        for (int o = 0; o < lead.length(); o++) {
+          out.print(' ');
+        }
+        out.println(s);
+      }
+      position += len;
+      length -= len;
+    }
+
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1bf69537/blur-shell/src/main/java/org/apache/blur/shell/Main.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
index 5759109..10e9e47 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
@@ -215,7 +215,9 @@ public class Main {
 
     try {
       ConsoleReader reader = new ConsoleReader();
-
+      
+      setConsoleReader(commands, reader);
+      
       reader.setPrompt("blur> ");
 
       String controllerConnectionString = null;
@@ -289,6 +291,12 @@ public class Main {
     }
   }
 
+  private static void setConsoleReader(Map<String, Command> cmds, ConsoleReader reader)
{
+    for (Entry<String, Command> c : cmds.entrySet()) {
+      c.getValue().setConsoleReader(reader);
+    }
+  }
+
   private static String loadControllerConnectionString() throws IOException {
     StringBuilder builder = new StringBuilder();
     InputStream inputStream = Main.class.getResourceAsStream("/controllers");


Mime
View raw message