cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r887502 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/cli: CliCompleter.java CliMain.java
Date Sat, 05 Dec 2009 05:27:48 GMT
Author: eevans
Date: Sat Dec  5 05:27:48 2009
New Revision: 887502

URL: http://svn.apache.org/viewvc?rev=887502&view=rev
Log:
cli command completion

Patch by eevans

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java   (with
props)
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java?rev=887502&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java Sat Dec
 5 05:27:48 2009
@@ -0,0 +1,51 @@
+/**
+ * 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.cassandra.cli;
+
+import jline.SimpleCompletor;
+
+public class CliCompleter extends SimpleCompletor
+{
+    private static String[] commands = {
+            "connect",
+            "describe keyspace",
+            "exit",
+            "help",
+            "quit",
+            "show config file",
+            "show cluster name",
+            "show keyspaces",
+            "show version",
+    };
+    private static String[] keyspaceCommands = {
+            "get",
+            "set",
+            "count",
+            "del"
+    };
+
+    public CliCompleter()
+    {
+        super(commands);
+    }
+    
+    String[] getKeyspaceCommands()
+    {
+        return keyspaceCommands;
+    }
+}

Propchange: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java?rev=887502&r1=887501&r2=887502&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java Sat Dec  5 05:27:48
2009
@@ -40,6 +40,7 @@
     private static Cassandra.Client thriftClient_ = null;
     private static CliSessionState css_ = new CliSessionState();
     private static CliClient cliClient_;
+    private static CliCompleter completer_ = new CliCompleter();
 
     // Establish a thrift connection to cassandra instance
     public static void connect(String server, int port)
@@ -71,6 +72,27 @@
 
         thriftClient_ = cassandraClient;
         cliClient_ = new CliClient(css_, thriftClient_);
+        
+        // Extend the completer with keyspace and column family data.
+        try
+        {
+            for (String keyspace : thriftClient_.get_string_list_property("keyspaces"))
+            {
+                // Ignore system column family
+                if (keyspace.equals("system"))
+                    continue;
+                
+                for (String cf : cliClient_.getCFMetaData(keyspace).keySet())
+                {
+                    for (String cmd : completer_.getKeyspaceCommands())
+                        completer_.addCandidateString(String.format("%s %s.%s", cmd, keyspace,
cf));
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            // Yes, we really do want to ignore any exceptions encountered here.
+        }
 
         css_.out.printf("Connected to %s/%d\n", server, port);
     }
@@ -133,7 +155,8 @@
             cliClient_ = new CliClient(css_, null);
         }
 
-        ConsoleReader reader = new ConsoleReader(); 
+        ConsoleReader reader = new ConsoleReader();
+        reader.addCompletor(completer_);
         reader.setBellEnabled(false);
 
         String historyFile = System.getProperty("user.home") + File.separator  + HISTORYFILE;



Mime
View raw message