incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: Added type ahead for commands that have a table name as the first argument.
Date Tue, 20 Aug 2013 13:35:12 GMT
Updated Branches:
  refs/heads/master 30702f091 -> dccd15276


Added type ahead for commands that have a table name as the first argument.


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

Branch: refs/heads/master
Commit: a5bbb48269c56e4a3e6855eee7d3b93d4e187586
Parents: 5e5200b
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Aug 20 09:33:29 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Aug 20 09:33:29 2013 -0400

----------------------------------------------------------------------
 .../blur/shell/AddColumnDefinitionCommand.java  |  14 +-
 .../org/apache/blur/shell/CommandCompletor.java | 144 +++++++++++++++++++
 .../org/apache/blur/shell/DeleteRowCommand.java |   2 +-
 .../apache/blur/shell/DescribeTableCommand.java |   2 +-
 .../blur/shell/EnableDisableTableCommand.java   |   2 +-
 .../org/apache/blur/shell/GetRowCommand.java    |   2 +-
 .../apache/blur/shell/LoadTestDataCommand.java  |   2 +-
 .../main/java/org/apache/blur/shell/Main.java   |   9 +-
 .../org/apache/blur/shell/MutateRowCommand.java |   2 +-
 .../org/apache/blur/shell/ParseCommand.java     |   2 +-
 .../org/apache/blur/shell/QueryCommand.java     |   2 +-
 .../apache/blur/shell/RemoveTableCommand.java   |   2 +-
 .../apache/blur/shell/SchemaTableCommand.java   |   3 +-
 .../shell/ShowDiffsOnlyCompletionHandler.java   | 108 ++++++++++++++
 .../apache/blur/shell/TableFirstArgCommand.java |  22 +++
 .../apache/blur/shell/TableStatsCommand.java    |   2 +-
 .../apache/blur/shell/TruncateTableCommand.java |   2 +-
 17 files changed, 298 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/AddColumnDefinitionCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/AddColumnDefinitionCommand.java
b/blur-shell/src/main/java/org/apache/blur/shell/AddColumnDefinitionCommand.java
index 611eea4..8d7ef16 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/AddColumnDefinitionCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/AddColumnDefinitionCommand.java
@@ -33,7 +33,7 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
 
-public class AddColumnDefinitionCommand extends Command {
+public class AddColumnDefinitionCommand extends Command implements TableFirstArgCommand {
 
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
@@ -73,12 +73,12 @@ public class AddColumnDefinitionCommand extends Command {
   @SuppressWarnings("static-access")
   private static CommandLine parse(String[] otherArgs, Writer out) {
     Options options = new Options();
-//    options.addOption(OptionBuilder.withArgName("family").hasArg().isRequired(true)
-//        .withDescription("* The family of the new column definition.").create("f"));
-//    options.addOption(OptionBuilder.withArgName("family").hasArg().isRequired(true)
-//        .withDescription("* The family of the new column definition.").create("f"));
-//    options.addOption(OptionBuilder.withArgName("column name").hasArg().isRequired(true)
-//        .withDescription("* The column name of the new column definition.").create("c"));
+    // options.addOption(OptionBuilder.withArgName("family").hasArg().isRequired(true)
+    // .withDescription("* The family of the new column definition.").create("f"));
+    // options.addOption(OptionBuilder.withArgName("family").hasArg().isRequired(true)
+    // .withDescription("* The family of the new column definition.").create("f"));
+    // options.addOption(OptionBuilder.withArgName("column name").hasArg().isRequired(true)
+    // .withDescription("* The column name of the new column definition.").create("c"));
     options.addOption(OptionBuilder.withArgName("sub column name").hasArg()
         .withDescription("The sub column name of the new column definition.").create("s"));
     options.addOption(OptionBuilder.withDescription(

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/CommandCompletor.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/CommandCompletor.java b/blur-shell/src/main/java/org/apache/blur/shell/CommandCompletor.java
new file mode 100644
index 0000000..c1c13b1
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/CommandCompletor.java
@@ -0,0 +1,144 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.blur.shell;
+
+import static jline.internal.Preconditions.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import jline.console.completer.Completer;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+
+public class CommandCompletor implements Completer {
+
+  private final Map<String, Command> _commands;
+  private final Iface _client;
+
+  public CommandCompletor(Map<String, Command> commands, Iface client) {
+    _commands = commands;
+    _client = client;
+  }
+
+  @Override
+  public int complete(final String buf, final int cursor, final List<CharSequence>
candidates) {
+    // buffer could be null
+    checkNotNull(candidates);
+    SortedSet<String> strings = sort(_commands.keySet());
+    if (buf == null) {
+      candidates.addAll(strings);
+    } else {
+      String buffer = buf.substring(0, cursor);
+      List<String> partialTableNames = isFirstArgPartialTableName(buffer);
+      if (partialTableNames != null && !partialTableNames.isEmpty()) {
+        candidates.addAll(partialTableNames);
+      } else {
+        for (String match : strings.tailSet(buffer)) {
+          if (!match.startsWith(buffer)) {
+            break;
+          }
+          candidates.add(match);
+        }
+      }
+    }
+    if (candidates.size() == 1) {
+      candidates.set(0, candidates.get(0) + " ");
+    }
+    return candidates.isEmpty() ? -1 : 0;
+  }
+
+  private List<String> isFirstArgPartialTableName(String buffer) {
+    String[] args = buffer.split("\\s+");
+    if (args.length > 2) {
+      return null;
+    }
+    String command = args[0];
+    Command cmd = _commands.get(command);
+    if (cmd == null) {
+      return null;
+    }
+    if (cmd instanceof TableFirstArgCommand) {
+      String tablePartial = "";
+      if (args.length == 2) {
+        tablePartial = args[1];
+      }
+      if (Main.cluster != null) {
+        try {
+          List<String> list = new ArrayList<String>(_client.tableListByCluster(Main.cluster));
+          Collections.sort(list);
+          List<String> results = new ArrayList<String>();
+          for (String table : list) {
+            if (table.startsWith(tablePartial)) {
+              results.add(args[0] + " " + table);
+            }
+          }
+          return results;
+        } catch (BlurException e) {
+          if (Main.debug) {
+            e.printStackTrace();
+          }
+          return null;
+        } catch (TException e) {
+          if (Main.debug) {
+            e.printStackTrace();
+          }
+          return null;
+        }
+      }
+    }
+    return null;
+  }
+
+  public int complete(Iface client, String potentialTable, List<CharSequence> candidates,
String commandName)
+      throws BlurException, TException {
+    SortedSet<String> tableList = new TreeSet<String>(client.tableList());
+    // buffer could be null
+    checkNotNull(candidates);
+
+    if (potentialTable == null) {
+      for (String table : tableList) {
+        candidates.add(commandName + " " + table);
+      }
+    } else {
+      for (String match : tableList.tailSet(potentialTable)) {
+        if (!match.startsWith(potentialTable)) {
+          break;
+        }
+        candidates.add(commandName + " " + match);
+      }
+    }
+
+    if (candidates.size() == 1) {
+      candidates.set(0, candidates.get(0) + " ");
+    }
+
+    return candidates.isEmpty() ? -1 : 0;
+  }
+
+  private SortedSet<String> sort(Set<String> set) {
+    return new TreeSet<String>(set);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java
index 2267093..b932a41 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java
@@ -25,7 +25,7 @@ import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.RowMutation;
 import org.apache.blur.thrift.generated.RowMutationType;
 
-public class DeleteRowCommand extends Command {
+public class DeleteRowCommand extends Command implements TableFirstArgCommand {
 
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
index 0a59cc8..84b5be2 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
@@ -25,7 +25,7 @@ import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.TableDescriptor;
 
-public class DescribeTableCommand extends Command {
+public class DescribeTableCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/EnableDisableTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/EnableDisableTableCommand.java
b/blur-shell/src/main/java/org/apache/blur/shell/EnableDisableTableCommand.java
index 0c3a1a9..10564cd 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/EnableDisableTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/EnableDisableTableCommand.java
@@ -24,7 +24,7 @@ import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 
-public class EnableDisableTableCommand extends Command {
+public class EnableDisableTableCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args)
       throws CommandException, TException, BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/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 62fa43a..26624f4 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
@@ -35,7 +35,7 @@ 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 {
+public class GetRowCommand extends Command implements TableFirstArgCommand {
 
   @Override
   public void doit(PrintWriter outPw, Blur.Iface client, String[] args) throws CommandException,
TException,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/LoadTestDataCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/LoadTestDataCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/LoadTestDataCommand.java
index f25a767..9589720 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/LoadTestDataCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/LoadTestDataCommand.java
@@ -25,7 +25,7 @@ import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.util.LoadData;
 
-public class LoadTestDataCommand extends Command {
+public class LoadTestDataCommand extends Command implements TableFirstArgCommand {
 
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/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 7eec71f..7673f64 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
@@ -33,8 +33,6 @@ import java.util.concurrent.TimeUnit;
 
 import jline.console.ConsoleReader;
 import jline.console.completer.Completer;
-import jline.console.completer.FileNameCompleter;
-import jline.console.completer.StringsCompleter;
 
 import org.apache.blur.shell.Command.CommandException;
 import org.apache.blur.shell.Main.QuitCommand.QuitCommandException;
@@ -399,13 +397,16 @@ public class Main {
 
         List<Completer> completors = new LinkedList<Completer>();
 
-        completors.add(new StringsCompleter(commands.keySet()));
-        completors.add(new FileNameCompleter());
+        // completors.add(new StringsCompleter(commands.keySet()));
+        // completors.add(new FileNameCompleter());
+        completors.add(new CommandCompletor(commands, client));
 
         for (Completer c : completors) {
           reader.addCompleter(c);
         }
 
+        reader.setCompletionHandler(new ShowDiffsOnlyCompletionHandler());
+
         String line;
         try {
           while ((line = reader.readLine()) != null) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java
index 27cd560..b03474f 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java
@@ -32,7 +32,7 @@ import org.apache.blur.thrift.generated.RecordMutationType;
 import org.apache.blur.thrift.generated.RowMutation;
 import org.apache.blur.thrift.generated.RowMutationType;
 
-public class MutateRowCommand extends Command {
+public class MutateRowCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args)
       throws CommandException, TException, BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/ParseCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/ParseCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/ParseCommand.java
index 379a6f0..050933c 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/ParseCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/ParseCommand.java
@@ -25,7 +25,7 @@ import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.Query;
 
-public class ParseCommand extends Command {
+public class ParseCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
index 30b7679..ecedb4d 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
@@ -36,7 +36,7 @@ import org.apache.blur.thrift.generated.HighlightOptions;
 import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.thrift.generated.Query;
 
-public class QueryCommand extends Command {
+public class QueryCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter outPw, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
index df562be..888c87a 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
@@ -24,7 +24,7 @@ import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 
-public class RemoveTableCommand extends Command {
+public class RemoveTableCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args)
       throws CommandException, TException, BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
index a165724..67606c3 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
@@ -20,7 +20,6 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
@@ -28,7 +27,7 @@ import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.ColumnDefinition;
 import org.apache.blur.thrift.generated.Schema;
 
-public class SchemaTableCommand extends Command {
+public class SchemaTableCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/ShowDiffsOnlyCompletionHandler.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/ShowDiffsOnlyCompletionHandler.java
b/blur-shell/src/main/java/org/apache/blur/shell/ShowDiffsOnlyCompletionHandler.java
new file mode 100644
index 0000000..bf7f5da
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/ShowDiffsOnlyCompletionHandler.java
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.blur.shell;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import jline.console.ConsoleReader;
+import jline.console.CursorBuffer;
+import jline.console.completer.CandidateListCompletionHandler;
+
+public class ShowDiffsOnlyCompletionHandler extends CandidateListCompletionHandler {
+
+  private final Method _method;
+
+  public ShowDiffsOnlyCompletionHandler() {
+    try {
+      _method = CandidateListCompletionHandler.class.getDeclaredMethod("getUnambiguousCompletions",
+          new Class[] { List.class });
+      _method.setAccessible(true);
+    } catch (SecurityException e) {
+      throw new RuntimeException(e);
+    } catch (NoSuchMethodException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Override
+  public boolean complete(final ConsoleReader reader, final List<CharSequence> candidates,
final int pos)
+      throws IOException {
+    CursorBuffer buf = reader.getCursorBuffer();
+
+    // if there is only one completion, then fill in the buffer
+    if (candidates.size() == 1) {
+      CharSequence value = candidates.get(0);
+
+      // fail if the only candidate is the same as the current buffer
+      if (value.equals(buf.toString())) {
+        return false;
+      }
+
+      CandidateListCompletionHandler.setBuffer(reader, value, pos);
+
+      return true;
+    } else if (candidates.size() > 1) {
+      String value = getUnambiguousCompletionsInternal(candidates);
+      CandidateListCompletionHandler.setBuffer(reader, value, pos);
+    }
+
+    printCandidates(reader, removeLeadingValues(buf.toString(), candidates));
+
+    // redraw the current console buffer
+    reader.drawLine();
+    return true;
+  }
+
+  private Collection<CharSequence> removeLeadingValues(String buf, List<CharSequence>
candidates) {
+    int index = buf.lastIndexOf(' ');
+    if (index < 0) {
+      return candidates;
+    }
+    List<CharSequence> result = new ArrayList<CharSequence>();
+    String prefix = buf.substring(0, index);
+    for (CharSequence c : candidates) {
+      String s = c.toString();
+      if (s.startsWith(prefix)) {
+        result.add(s.substring(index + 1));
+      } else {
+        result.add(s);
+      }
+    }
+    return result;
+  }
+
+  private String getUnambiguousCompletionsInternal(List<CharSequence> candidates) {
+    try {
+      return (String) _method.invoke(this, candidates);
+    } catch (IllegalArgumentException e) {
+      throw new RuntimeException(e);
+    } catch (IllegalAccessException e) {
+      throw new RuntimeException(e);
+    } catch (InvocationTargetException e) {
+      throw new RuntimeException(e);
+    }
+
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/TableFirstArgCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TableFirstArgCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/TableFirstArgCommand.java
new file mode 100644
index 0000000..19b9803
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/TableFirstArgCommand.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.blur.shell;
+
+public interface TableFirstArgCommand {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
index 95ba985..129f266 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
@@ -25,7 +25,7 @@ import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.TableStats;
 
-public class TableStatsCommand extends Command {
+public class TableStatsCommand extends Command implements TableFirstArgCommand {
   private static final double _1KB = 1000;
   private static final double _1MB = _1KB * 1000;
   private static final double _1GB = _1MB * 1000;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a5bbb482/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
index 807f8b9..8548b9e 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
@@ -26,7 +26,7 @@ import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.TableDescriptor;
 
-public class TruncateTableCommand extends Command {
+public class TruncateTableCommand extends Command implements TableFirstArgCommand {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {


Mime
View raw message