mirror of https://github.com/apache/cassandra
cli command completion
Patch by eevans git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@887502 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bf6ac62695
commit
bbfcb18ae5
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ public class CliMain
|
|||
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 @@ public class CliMain
|
|||
|
||||
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 @@ public class CliMain
|
|||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue