Author: jbellis
Date: Fri Nov 19 17:07:53 2010
New Revision: 1036945

URL: http://svn.apache.org/viewvc?rev=1036945&view=rev
Log:
multi-line cli commands, other cleanup
patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-1742

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
    
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompiler.java
    
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliMain.java
    
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
    
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Fri Nov 19 17:07:53 2010
@@ -43,6 +43,7 @@ dev
  * fix for bootstrap when no non-system tables are defined (CASSANDRA-1732)
  * handle replica unavailability in index scan (CASSANDRA-1755)
  * fix service initialization order deadlock (CASSANDRA-1756)
+ * multi-line cli commands (CASSANDRA-1742)
 
 
 0.7.0-beta3

Modified: 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
 (original)
+++ 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
 Fri Nov 19 17:07:53 2010
@@ -226,7 +226,7 @@ public class CliClient extends CliUserHe
         Tree columnFamilySpec = statement.getChild(0);
 
         String key = CliCompiler.getKey(columnFamilySpec);
-        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
+        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, 
keyspacesMap.get(keySpace).cf_defs);
         int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
        
         ColumnParent colParent = new 
ColumnParent(columnFamily).setSuper_column((ByteBuffer) null);
@@ -253,7 +253,7 @@ public class CliClient extends CliUserHe
         Tree columnFamilySpec = statement.getChild(0);
 
         String key = CliCompiler.getKey(columnFamilySpec);
-        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
+        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, 
keyspacesMap.get(keySpace).cf_defs);
         int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
 
         byte[] superColumnName = null;
@@ -370,7 +370,7 @@ public class CliClient extends CliUserHe
             return;
 
         Tree columnFamilySpec = statement.getChild(0);
-        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
+        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, 
keyspacesMap.get(keySpace).cf_defs);
         ByteBuffer key = getKeyAsBytes(columnFamily, 
columnFamilySpec.getChild(1));
         int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
         CfDef cfDef = getCfDef(columnFamily);
@@ -562,7 +562,7 @@ public class CliClient extends CliUserHe
         Tree columnFamilySpec = statement.getChild(0);
         Tree keyTree = columnFamilySpec.getChild(1); // could be a function or 
regular text
 
-        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
+        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, 
keyspacesMap.get(keySpace).cf_defs);
         CfDef cfDef = getCfDef(columnFamily);
         int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
         String value = 
CliUtils.unescapeSQLString(statement.getChild(1).getText());
@@ -693,10 +693,10 @@ public class CliClient extends CliUserHe
         if (!CliMain.isConnected())
             return;
 
-        String keyspaceName = statement.getChild(0).getText();
-        
         try
         {
+            String keyspaceName = CliCompiler.getKeySpace(statement, 
thriftClient.describe_keyspaces());
+
             KsDef currentKsDef = getKSMetaData(keyspaceName);
             KsDef updatedKsDef = updateKsDefAttributes(statement, 
currentKsDef);
 
@@ -722,8 +722,9 @@ public class CliClient extends CliUserHe
         if (!CliMain.isConnected() || !hasKeySpace())
             return;
 
+        String cfName = CliCompiler.getColumnFamily(statement, 
keyspacesMap.get(keySpace).cf_defs);
         // first child is a column family name
-        CfDef cfDef = getCfDef(statement.getChild(0).getText());
+        CfDef cfDef = getCfDef(cfName);
 
         try
         {
@@ -874,7 +875,7 @@ public class CliClient extends CliUserHe
         if (!CliMain.isConnected())
             return;
 
-        String keyspaceName = statement.getChild(0).getText();
+        String keyspaceName = CliCompiler.getKeySpace(statement, 
thriftClient.describe_keyspaces());
         
sessionState.out.println(thriftClient.system_drop_keyspace(keyspaceName));
     }
 
@@ -891,8 +892,8 @@ public class CliClient extends CliUserHe
         if (!CliMain.isConnected() || !hasKeySpace())
             return;
 
-        String columnName = statement.getChild(0).getText();
-        
sessionState.out.println(thriftClient.system_drop_column_family(columnName));
+        String cfName = CliCompiler.getColumnFamily(statement, 
keyspacesMap.get(keySpace).cf_defs);
+        
sessionState.out.println(thriftClient.system_drop_column_family(cfName));
     }
 
     private void executeList(Tree statement)
@@ -902,7 +903,7 @@ public class CliClient extends CliUserHe
             return;
         
         // extract column family
-        String columnFamily = statement.getChild(0).getText();
+        String columnFamily = CliCompiler.getColumnFamily(statement, 
keyspacesMap.get(keySpace).cf_defs);
 
         String rawStartKey = "";
         String rawEndKey = "";
@@ -971,7 +972,7 @@ public class CliClient extends CliUserHe
             return;
 
         // getting CfDef, it will fail if there is no such column family in 
current keySpace. 
-        CfDef cfDef = getCfDef(columnFamily);
+        CfDef cfDef = getCfDef(CliCompiler.getColumnFamily(columnFamily, 
keyspacesMap.get(keySpace).cf_defs));
 
         try
         {
@@ -998,7 +999,8 @@ public class CliClient extends CliUserHe
         if (!CliMain.isConnected() || !hasKeySpace())
             return;
 
-        CfDef columnFamily = getCfDef(statement.getChild(0).getText());
+        String cfName = CliCompiler.getColumnFamily(statement, 
keyspacesMap.get(keySpace).cf_defs);
+        CfDef columnFamily = getCfDef(cfName);
 
         // VALIDATOR | COMPARATOR | KEYS | SUB_COMPARATOR
         String assumptionElement = 
statement.getChild(1).getText().toUpperCase();
@@ -1059,8 +1061,12 @@ public class CliClient extends CliUserHe
     {
         if (!CliMain.isConnected())
             return;
-        
-        for (KsDef keySpace : thriftClient.describe_keyspaces()) {
+
+        List<KsDef> keySpaces = thriftClient.describe_keyspaces();
+
+        Collections.sort(keySpaces, new KsDefNamesComparator());
+        for (KsDef keySpace : keySpaces)
+        {
             describeKeySpace(keySpace.name, keySpace);
         }
     }
@@ -1111,7 +1117,7 @@ public class CliClient extends CliUserHe
         int childCount = statement.getChildCount();
         String keySpaceName, username = null, password = null;
 
-        // Get table name
+        // Get keyspace name
         keySpaceName = statement.getChild(0).getText();
         
         if (childCount == 3) {
@@ -1129,10 +1135,11 @@ public class CliClient extends CliUserHe
         {
                AuthenticationRequest authRequest;
                Map<String, String> credentials = new HashMap<String, String>();
-               
-               
-               thriftClient.set_keyspace(keySpaceName);
-   
+
+            keySpaceName = CliCompiler.getKeySpace(keySpaceName, 
thriftClient.describe_keyspaces());
+
+            thriftClient.set_keyspace(keySpaceName);
+
                if (username != null && password != null) 
                {
                    /* remove quotes */
@@ -1186,6 +1193,7 @@ public class CliClient extends CliUserHe
             sessionState.out.println("  Replication Factor: " + 
ks_def.replication_factor);
             sessionState.out.println("  Column Families:");
 
+            Collections.sort(ks_def.cf_defs, new CfDefNamesComparator());
             for (CfDef cf_def : ks_def.cf_defs)
             {
                 sessionState.out.printf("    ColumnFamily: %s%s\n", 
cf_def.name, cf_def.column_type.equals("Super") ? " (Super)" : "");
@@ -1254,13 +1262,13 @@ public class CliClient extends CliUserHe
         }
     }
     // DESCRIBE KEYSPACE <keyspace_name> 
-    private void executeDescribeKeySpace(Tree statement) throws TException
+    private void executeDescribeKeySpace(Tree statement) throws TException, 
InvalidRequestException
     {
         if (!CliMain.isConnected())
             return;
 
         // Get keySpace name
-        String keySpaceName = statement.getChild(0).getText();
+        String keySpaceName = CliCompiler.getKeySpace(statement, 
thriftClient.describe_keyspaces());
 
         if( keySpaceName == null ) {
             sessionState.out.println("Keyspace argument required");
@@ -1795,7 +1803,7 @@ public class CliClient extends CliUserHe
      * @throws NoSuchFieldException - column not found
      */
     private void printSliceList(CfDef columnFamilyDef, List<KeySlice> slices)
-    throws NotFoundException, TException, IllegalAccessException, 
InstantiationException, NoSuchFieldException
+            throws NotFoundException, TException, IllegalAccessException, 
InstantiationException, NoSuchFieldException
     {
         AbstractType validator;
         String columnFamilyName = columnFamilyDef.getName();
@@ -1887,4 +1895,20 @@ public class CliClient extends CliUserHe
         AbstractType keyComparator = this.cfKeysComparators.get(columnFamily);
         return getBytesAccordingToType(key, keyComparator);
     }
+
+    private class KsDefNamesComparator implements Comparator<KsDef>
+    {
+        public int compare(KsDef a, KsDef b)
+        {
+            return a.name.compareTo(b.name);
+        }
+    }
+
+    private class CfDefNamesComparator implements Comparator<CfDef>
+    {
+        public int compare(CfDef a, CfDef b)
+        {
+            return a.name.compareTo(b.name);
+        }
+    }
 }

Modified: 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompiler.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompiler.java?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompiler.java
 (original)
+++ 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompiler.java
 Fri Nov 19 17:07:53 2010
@@ -20,6 +20,10 @@ package org.apache.cassandra.cli;
 
 import org.antlr.runtime.*;
 import org.antlr.runtime.tree.*;
+import org.apache.cassandra.thrift.KsDef;
+import org.apache.cassandra.thrift.CfDef;
+
+import java.util.List;
 
 
 public class CliCompiler
@@ -88,9 +92,62 @@ public class CliCompiler
      * NODE_COLUMN_ACCESS related functions.
      */
 
-    public static String getColumnFamily(Tree astNode)
+    public static String getColumnFamily(Tree astNode, List<CfDef> cfDefs)
+    {
+        return getColumnFamily(astNode.getChild(0).getText(), cfDefs);
+    }
+
+    public static String getColumnFamily(String cfName, List<CfDef> cfDefs)
+    {
+        int matches = 0;
+        String lastMatchedName = "";
+
+        for (CfDef cfDef : cfDefs)
+        {
+            if (cfDef.name.equals(cfName))
+            {
+                return cfName;
+            }
+            else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
+            {
+                lastMatchedName = cfDef.name;
+                matches++;
+            }
+        }
+
+        if (matches > 1 || matches == 0)
+            throw new RuntimeException(cfName + " not found in current 
keyspace.");
+
+        return lastMatchedName;
+    }
+
+    public static String getKeySpace(Tree statement, List<KsDef> keyspaces)
     {
-        return astNode.getChild(0).getText();
+        return getKeySpace(statement.getChild(0).getText(), keyspaces);
+    }
+
+    public static String getKeySpace(String ksName, List<KsDef> keyspaces)
+    {
+        int matches = 0;
+        String lastMatchedName = "";
+
+        for (KsDef ksDef : keyspaces)
+        {
+            if (ksDef.name.equals(ksName))
+            {
+                return ksName;
+            }
+            else if (ksDef.name.toUpperCase().equals(ksName.toUpperCase()))
+            {
+                lastMatchedName = ksDef.name;
+                matches++;
+            }
+        }
+
+        if (matches > 1 || matches == 0)
+            throw new RuntimeException("Keyspace '" + ksName + "' not found.");
+
+        return lastMatchedName;
     }
 
     public static String getKey(Tree astNode)

Modified: 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliMain.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliMain.java?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliMain.java 
(original)
+++ 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliMain.java 
Fri Nov 19 17:07:53 2010
@@ -93,7 +93,9 @@ public class CliMain
         
         if (sessionState.keyspace != null)
         {
-            try {
+            try
+            {
+                sessionState.keyspace = 
CliCompiler.getKeySpace(sessionState.keyspace, 
thriftClient.describe_keyspaces());;
                 thriftClient.set_keyspace(sessionState.keyspace);
                 cliClient.setKeySpace(sessionState.keyspace);
                 
updateCompletor(CliUtils.getCfNamesByKeySpace(cliClient.getKSMetaData(sessionState.keyspace)));
@@ -284,15 +286,7 @@ public class CliMain
                 return;
             }
 
-            BufferedReader reader = new BufferedReader(fileReader);
-
-            String statement;
-
-            while ((statement = reader.readLine()) != null)
-            {
-                processStatement(statement);
-            }
-
+            evaluateFileStatements(new BufferedReader(fileReader));
             return;
         }
 
@@ -322,10 +316,57 @@ public class CliMain
 
         printBanner();
 
-        String line;
-        while ((line = reader.readLine(getPrompt(cliClient))) != null)
+        String prompt;
+        String line = "";
+        String currentStatement = "";
+        boolean inCompoundStatement = false;
+
+        while (line != null)
+        {
+            prompt = (inCompoundStatement) ? "\t" : getPrompt(cliClient);
+
+            line = reader.readLine(prompt).trim();
+
+            if (line.isEmpty())
+                continue;
+
+            currentStatement += line;
+
+            if (line.endsWith(";"))
+            {
+                processStatement(currentStatement);
+                currentStatement = "";
+                inCompoundStatement = false;
+            }
+            else
+            {
+                currentStatement += " "; // ready for new line
+                inCompoundStatement = true;
+            }
+        }
+    }
+
+    private static void evaluateFileStatements(BufferedReader reader) throws 
IOException
+    {
+        String line = "";
+        String currentStatement = "";
+
+        while ((line = reader.readLine()) != null)
         {
-            processStatement(line);
+            if (line.isEmpty())
+                continue;
+
+            currentStatement += line;
+
+            if (line.endsWith(";"))
+            {
+                processStatement(currentStatement);
+                currentStatement = "";
+            }
+            else
+            {
+                currentStatement += " "; // ready for new line
+            }
         }
     }
 

Modified: 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
 (original)
+++ 
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
 Fri Nov 19 17:07:53 2010
@@ -79,55 +79,55 @@ public class CliUserHelp {
             switch(helpType)
             {
             case CliParser.NODE_HELP:
-                state.out.println("help <command>\n");
+                state.out.println("help <command>;\n");
                 state.out.println("Display the general help page with a list 
of available commands.");
                 break;
             case CliParser.NODE_CONNECT:
-                state.out.println("connect <hostname>/<port>\n");
+                state.out.println("connect <hostname>/<port>;\n");
                 state.out.println("Connect to the specified host on the 
specified port.\n");
                 state.out.println("example:");
-                state.out.println("connect localhost/9160");
+                state.out.println("connect localhost/9160;");
                 break;
 
             case CliParser.NODE_USE_TABLE:
-                state.out.println("use <keyspace>");
-                state.out.println("use <keyspace> <username> '<password>'\n");
+                state.out.println("use <keyspace>;");
+                state.out.println("use <keyspace> <username> '<password>';\n");
                 state.out.println("Switch to the specified keyspace. The 
optional username and password fields");
                 state.out.println("are needed when performing 
authentication.\n");
                 break;
 
             case CliParser.NODE_DESCRIBE_TABLE:
-                state.out.println("describe keyspace <keyspace>\n");
+                state.out.println("describe keyspace <keyspace>;\n");
                 state.out.println("Show additional information about the 
specified keyspace.\n");
                 state.out.println("example:");
-                state.out.println("describe keyspace system");
+                state.out.println("describe keyspace system;");
                 break;
 
             case CliParser.NODE_EXIT:
-                state.out.println("exit");
-                state.out.println("quit\n");
+                state.out.println("exit;");
+                state.out.println("quit;\n");
                 state.out.println("Exit this utility.");
                 break;
 
             case CliParser.NODE_SHOW_CLUSTER_NAME:
-                state.out.println("show cluster name\n");
+                state.out.println("show cluster name;\n");
                 state.out.println("Displays the name of the currently 
connected cluster.");
                 break;
 
             case CliParser.NODE_SHOW_VERSION:
-                state.out.println("show api version\n");
+                state.out.println("show api version;\n");
                 state.out.println("Displays the API version number.");
                 break;
 
             case CliParser.NODE_SHOW_KEYSPACES:
-                state.out.println("show keyspaces\n");
+                state.out.println("show keyspaces;\n");
                 state.out.println("Displays a list of the keyspaces available 
on the currently connected cluster.");
                 break;
 
             case CliParser.NODE_ADD_KEYSPACE:
-                state.out.println("create keyspace <keyspace>");
-                state.out.println("create keyspace <keyspace> with 
<att1>=<value1>");
-                state.out.println("create keyspace <keyspace> with 
<att1>=<value1> and <att2>=<value2> ...\n");
+                state.out.println("create keyspace <keyspace>;");
+                state.out.println("create keyspace <keyspace> with 
<att1>=<value1>;");
+                state.out.println("create keyspace <keyspace> with 
<att1>=<value1> and <att2>=<value2> ...;\n");
                 state.out.println("Create a new keyspace with the specified 
values for the given set of attributes.\n");
                 state.out.println("valid attributes are:");
                 state.out.println("    replication_factor: to how many nodes 
should entries to this keyspace be");
@@ -141,13 +141,13 @@ public class CliUserHelp {
                 state.out.println("example:");
                 state.out.println("create keyspace foo with replication_factor 
= 3 and ");
                 state.out.println("        placement_strategy = 
'org.apache.cassandra.locator.SimpleStrategy'");
-                state.out.println("        and strategy_options=[{DC1:2, 
DC2:2}]");
+                state.out.println("        and strategy_options=[{DC1:2, 
DC2:2}];");
                 break;
 
             case CliParser.NODE_UPDATE_KEYSPACE:
-                state.out.println("update keyspace <keyspace>");
-                state.out.println("update keyspace <keyspace> with 
<att1>=<value1>");
-                state.out.println("update keyspace <keyspace> with 
<att1>=<value1> and <att2>=<value2> ...\n");
+                state.out.println("update keyspace <keyspace>;");
+                state.out.println("update keyspace <keyspace> with 
<att1>=<value1>;");
+                state.out.println("update keyspace <keyspace> with 
<att1>=<value1> and <att2>=<value2> ...;\n");
                 state.out.println("Update a keyspace with the specified values 
for the given set of attributes.\n");
                 state.out.println("valid attributes are:");
                 state.out.println("    replication_factor: to how many nodes 
should entries to this keyspace be");
@@ -161,13 +161,13 @@ public class CliUserHelp {
                 state.out.println("example:");
                 state.out.println("update keyspace foo with replication_factor 
= 2 and ");
                 state.out.println("        placement_strategy = 
'org.apache.cassandra.locator.LocalStrategy'");
-                state.out.println("        and strategy_options=[{DC1:1, 
DC2:4, DC3:2}]");
+                state.out.println("        and strategy_options=[{DC1:1, 
DC2:4, DC3:2}];");
                 break;
 
             case CliParser.NODE_ADD_COLUMN_FAMILY:
-                state.out.println("create column family Bar");
-                state.out.println("create column family Bar with 
<att1>=<value1>");
-                state.out.println("create column family Bar with 
<att1>=<value1> and <att2>=<value2>...\n");
+                state.out.println("create column family Bar;");
+                state.out.println("create column family Bar with 
<att1>=<value1>;");
+                state.out.println("create column family Bar with 
<att1>=<value1> and <att2>=<value2>...;\n");
                 state.out.println("Create a new column family with the 
specified values for the given set of");
                 state.out.println("attributes. Note that you must be using a 
keyspace.\n");
                 state.out.println("valid attributes are:");
@@ -179,17 +179,17 @@ public class CliUserHelp {
                 state.out.println("                          index_type 
(integer), index_name.");
                 state.out.println("example:\n");
                 state.out.println("create column family Bar with column_type = 
'Super' and comparator = 'AsciiType'");
-                state.out.println("      and rows_cached = 10000");
-                state.out.println("create column family Baz with comparator = 
'LongType' and rows_cached = 10000");
+                state.out.println("      and rows_cached = 10000;");
+                state.out.println("create column family Baz with comparator = 
'LongType' and rows_cached = 10000;");
                 state.out.print("create column family Foo with 
comparator=LongType and column_metadata=");
                 state.out.print("[{ column_name:Test, 
validation_class:IntegerType, index_type:0, index_name:IdxName");
-                state.out.println("}, { column_name:'other name', 
validation_class:LongType }]");
+                state.out.println("}, { column_name:'other name', 
validation_class:LongType }];");
                 break;
 
             case CliParser.NODE_UPDATE_COLUMN_FAMILY:
-                state.out.println("update column family Bar");
-                state.out.println("update column family Bar with 
<att1>=<value1>");
-                state.out.println("update column family Bar with 
<att1>=<value1> and <att2>=<value2>...\n");
+                state.out.println("update column family Bar;");
+                state.out.println("update column family Bar with 
<att1>=<value1>;");
+                state.out.println("update column family Bar with 
<att1>=<value1> and <att2>=<value2>...;\n");
                 state.out.println("Update a column family with the specified 
values for the given set of");
                 state.out.println("attributes. Note that you must be using a 
keyspace.\n");
                 state.out.println("valid attributes are:");
@@ -206,103 +206,103 @@ public class CliUserHelp {
                 state.out.println("example:\n");
                 state.out.print("update column family Foo with 
column_metadata=");
                 state.out.print("[{ column_name:Test, 
validation_class:IntegerType, index_type:0, index_name:IdxName");
-                state.out.println("}] and rows_cached=100 and comment='this is 
helpful comment.'");
+                state.out.println("}] and rows_cached=100 and comment='this is 
helpful comment.';");
                 break;
 
             case CliParser.NODE_DEL_KEYSPACE:
-                state.out.println("drop keyspace <keyspace>\n");
+                state.out.println("drop keyspace <keyspace>;\n");
                 state.out.println("Drops the specified keyspace.\n");
                 state.out.println("example:");
-                state.out.println("drop keyspace foo");
+                state.out.println("drop keyspace foo;");
                 break;
 
             case CliParser.NODE_DEL_COLUMN_FAMILY:
-                state.out.println("drop column family <name>\n");
+                state.out.println("drop column family <name>;\n");
                 state.out.println("Drops the specified column family.\n");
                 state.out.println("example:");
-                state.out.println("drop column family foo");
+                state.out.println("drop column family foo;");
                 break;
 
             case CliParser.NODE_THRIFT_GET :
-                state.out.println("get <cf>['<key>']");
-                state.out.println("get <cf>['<key>']['<col>'] (as <type>)*");
-                state.out.println("get <cf>['<key>']['<super>']");
-                state.out.println("get <cf>['<key>'][<function>]");
-                state.out.println("get 
<cf>['<key>'][<function>(<super>)][<function>(<col>)]");
-                state.out.println("get <cf> where <column> = <value> [and 
<column> > <value> and ...] [limit <integer>]");
+                state.out.println("get <cf>['<key>'];");
+                state.out.println("get <cf>['<key>']['<col>'] (as <type>)*;");
+                state.out.println("get <cf>['<key>']['<super>'];");
+                state.out.println("get <cf>['<key>'][<function>];");
+                state.out.println("get 
<cf>['<key>'][<function>(<super>)][<function>(<col>)];");
+                state.out.println("get <cf> where <column> = <value> [and 
<column> > <value> and ...] [limit <integer>];");
                 state.out.println("Default LIMIT is 100. Available operations: 
=, >, >=, <, <=\n");
-                state.out.println("get <cf>['<key>']['<super>']['<col>'] (as 
<type>)*");
+                state.out.println("get <cf>['<key>']['<super>']['<col>'] (as 
<type>)*;");
                 state.out.print("Note: `as <type>` is optional, it dynamically 
converts column value to the specified type");
                 state.out.println(", column value validator will be set to 
<type>.");
                 state.out.println("Available functions: " + 
CliClient.Function.getFunctionNames());
                 state.out.println("Available types: IntegerType, LongType, 
UTF8Type, ASCIIType, TimeUUIDType, LexicalUUIDType.\n");
                 state.out.println("examples:");
-                state.out.println("get bar[testkey]");
-                state.out.println("get bar[testkey][test_column] as 
IntegerType");
-                state.out.println("get bar[testkey][utf8(hello)]");
+                state.out.println("get bar[testkey];");
+                state.out.println("get bar[testkey][test_column] as 
IntegerType;");
+                state.out.println("get bar[testkey][utf8(hello)];");
                 break;
 
             case CliParser.NODE_THRIFT_SET:
-                state.out.println("set <cf>['<key>']['<col>'] = <value>");
-                state.out.println("set <cf>['<key>']['<super>']['<col>'] = 
<value>");
-                state.out.println("set <cf>['<key>']['<col>'] = 
<function>(<argument>)");
-                state.out.println("set <cf>['<key>']['<super>']['<col>'] = 
<function>(<argument>)");
-                state.out.println("set <cf>[<key>][<function>(<col>)] = 
<value> || <function>");
+                state.out.println("set <cf>['<key>']['<col>'] = <value>;");
+                state.out.println("set <cf>['<key>']['<super>']['<col>'] = 
<value>;");
+                state.out.println("set <cf>['<key>']['<col>'] = 
<function>(<argument>);");
+                state.out.println("set <cf>['<key>']['<super>']['<col>'] = 
<function>(<argument>);");
+                state.out.println("set <cf>[<key>][<function>(<col>)] = 
<value> || <function>;");
                 state.out.println("Available functions: " + 
CliClient.Function.getFunctionNames() + "\n");
                 state.out.println("examples:");
-                state.out.println("set bar['testkey']['my super']['test 
col']='this is a test'");
-                state.out.println("set baz['testkey']['test col']='this is 
also a test'");
-                state.out.println("set diz[testkey][testcol] = utf8('this is 
utf8 string.')");
-                state.out.println("set bar[testkey][timeuuid()] = utf('hello 
world')");
+                state.out.println("set bar['testkey']['my super']['test 
col']='this is a test';");
+                state.out.println("set baz['testkey']['test col']='this is 
also a test';");
+                state.out.println("set diz[testkey][testcol] = utf8('this is 
utf8 string.');");
+                state.out.println("set bar[testkey][timeuuid()] = utf('hello 
world');");
                 break;
 
             case CliParser.NODE_THRIFT_DEL:
-                state.out.println("del <cf>['<key>'] ");
-                state.out.println("del <cf>['<key>']['<col>'] ");
-                state.out.println("del <cf>['<key>']['<super>']['<col>']\n");
+                state.out.println("del <cf>['<key>'];");
+                state.out.println("del <cf>['<key>']['<col>'];");
+                state.out.println("del <cf>['<key>']['<super>']['<col>'];\n");
                 state.out.println("Deletes a record, a column, or a 
subcolumn.\n");
                 state.out.println("example:");
-                state.out.println("del bar['testkey']['my super']['test 
col']");
-                state.out.println("del baz['testkey']['test col']");
-                state.out.println("del baz['testkey']");
+                state.out.println("del bar['testkey']['my super']['test 
col'];");
+                state.out.println("del baz['testkey']['test col'];");
+                state.out.println("del baz['testkey'];");
                 break;
 
             case CliParser.NODE_THRIFT_COUNT:
-                state.out.println("count <cf>['<key>']");
-                state.out.println("count <cf>['<key>']['<super>']\n");
+                state.out.println("count <cf>['<key>'];");
+                state.out.println("count <cf>['<key>']['<super>'];\n");
                 state.out.println("Count the number of columns in the 
specified key or subcolumns in the specified");
                 state.out.println("super column.\n");
                 state.out.println("example:");
-                state.out.println("count bar['testkey']['my super']");
-                state.out.println("count baz['testkey']");
+                state.out.println("count bar['testkey']['my super'];");
+                state.out.println("count baz['testkey'];");
                 break;
 
             case CliParser.NODE_LIST:
-                state.out.println("list <cf>");
-                state.out.println("list <cf>[<startKey>:]");
-                state.out.println("list <cf>[<startKey>:<endKey>]");
-                state.out.println("list ... limit N");
+                state.out.println("list <cf>;");
+                state.out.println("list <cf>[<startKey>:];");
+                state.out.println("list <cf>[<startKey>:<endKey>];");
+                state.out.println("list ... limit N;");
                 state.out.println("List a range of rows in the column or 
supercolumn family.\n");
                 state.out.println("example:");
-                state.out.println("list Users[j:] limit 40");
+                state.out.println("list Users[j:] limit 40;");
                 break;
 
             case CliParser.NODE_TRUNCATE:
-                state.out.println("truncate <column_family>");
+                state.out.println("truncate <column_family>;");
                 state.out.println("Truncate specified column family.\n");
                 state.out.println("example:");
-                state.out.println("truncate Category");
+                state.out.println("truncate Category;");
                 break;
 
             case CliParser.NODE_ASSUME:
-                state.out.println("assume <column_family> comparator as 
<type>");
-                state.out.println("assume <column_family> sub_comparator as 
<type>");
-                state.out.println("assume <column_family> validator as 
<type>");
-                state.out.println("assume <column_family> keys as <type>\n");
+                state.out.println("assume <column_family> comparator as 
<type>;");
+                state.out.println("assume <column_family> sub_comparator as 
<type>;");
+                state.out.println("assume <column_family> validator as 
<type>;");
+                state.out.println("assume <column_family> keys as <type>;\n");
                 state.out.println("Assume one of the attributes (comparator, 
sub_comparator, validator or keys)");
                 state.out.println("of the given column family to match 
specified type. Available types: " + CliClient.Function.getFunctionNames());
                 state.out.println("example:");
-                state.out.println("assume Users comparator as lexicaluuid");
+                state.out.println("assume Users comparator as lexicaluuid;");
                 break;
 
             default:
@@ -314,47 +314,47 @@ public class CliUserHelp {
         {
             state.out.println("List of all CLI commands:");
             state.out.println("?                                               
           Display this message.");
-            state.out.println("help                                            
              Display this help.");
-            state.out.println("help <command>                          Display 
detailed, command-specific help.");
-            state.out.println("connect <hostname>/<port>                       
      Connect to thrift service.");
-            state.out.println("use <keyspace> [<username> 'password']          
           Switch to a keyspace.");
-            state.out.println("describe keyspace <keyspacename>                
              Describe keyspace.");
-            state.out.println("exit                                            
                       Exit CLI.");
-            state.out.println("quit                                            
                       Exit CLI.");
-            state.out.println("show cluster name                               
           Display cluster name.");
-            state.out.println("show keyspaces                                  
         Show list of keyspaces.");
-            state.out.println("show api version                                
        Show server API version.");
-            state.out.println("create keyspace <keyspace> [with 
<att1>=<value1> [and <att2>=<value2> ...]]");
+            state.out.println("help;                                           
               Display this help.");
+            state.out.println("help <command>;                          
Display detailed, command-specific help.");
+            state.out.println("connect <hostname>/<port>;                      
       Connect to thrift service.");
+            state.out.println("use <keyspace> [<username> 'password'];         
            Switch to a keyspace.");
+            state.out.println("describe keyspace <keyspacename>;               
               Describe keyspace.");
+            state.out.println("exit;                                           
                        Exit CLI.");
+            state.out.println("quit;                                           
                        Exit CLI.");
+            state.out.println("show cluster name;                              
            Display cluster name.");
+            state.out.println("show keyspaces;                                 
          Show list of keyspaces.");
+            state.out.println("show api version;                               
         Show server API version.");
+            state.out.println("create keyspace <keyspace> [with 
<att1>=<value1> [and <att2>=<value2> ...]];");
             state.out.println("                Add a new keyspace with the 
specified attribute(s) and value(s).");
-            state.out.println("update keyspace <keyspace> [with 
<att1>=<value1> [and <att2>=<value2> ...]]");
+            state.out.println("update keyspace <keyspace> [with 
<att1>=<value1> [and <att2>=<value2> ...]];");
             state.out.println("                 Update a keyspace with the 
specified attribute(s) and value(s).");
-            state.out.println("create column family <cf> [with <att1>=<value1> 
[and <att2>=<value2> ...]]");
+            state.out.println("create column family <cf> [with <att1>=<value1> 
[and <att2>=<value2> ...]];");
             state.out.println("        Create a new column family with the 
specified attribute(s) and value(s).");
-            state.out.println("update column family <cf> [with <att1>=<value1> 
[and <att2>=<value2> ...]]");
+            state.out.println("update column family <cf> [with <att1>=<value1> 
[and <att2>=<value2> ...]];");
             state.out.println("            Update a column family with the 
specified attribute(s) and value(s).");
-            state.out.println("drop keyspace <keyspace>                        
              Delete a keyspace.");
-            state.out.println("drop column family <cf>                         
         Delete a column family.");
-            state.out.println("get <cf>['<key>']                               
         Get a slice of columns.");
-            state.out.println("get <cf>['<key>']['<super>']                    
     Get a slice of sub columns.");
-            state.out.println("get <cf> where <column> = <value> [and <column> 
> <value> and ...] [limit int]. ");
-            state.out.println("get <cf>['<key>']['<col>'] (as <type>)*         
             Get a column value.");
-            state.out.println("get <cf>['<key>']['<super>']['<col>'] (as 
<type>)*       Get a sub column value.");
-            state.out.println("set <cf>['<key>']['<col>'] = <value>            
                   Set a column.");
-            state.out.println("set <cf>['<key>']['<super>']['<col>'] = <value> 
               Set a sub column.");
-            state.out.println("del <cf>['<key>']                               
                  Delete record.");
-            state.out.println("del <cf>['<key>']['<col>']                      
                  Delete column.");
-            state.out.println("del <cf>['<key>']['<super>']['<col>']           
              Delete sub column.");
-            state.out.println("count <cf>['<key>']                             
        Count columns in record.");
-            state.out.println("count <cf>['<key>']['<super>']                  
Count columns in a super column.");
-            state.out.println("truncate <column_family>                       
Truncate specified column family.");
-            state.out.println("assume <column_family> <attribute> as <type>");
-            state.out.println("Assume one of the attributes of the given 
column family to match specified type.");
-            state.out.println("list <cf>                                    
List all rows in the column family.");
-            state.out.println("list <cf>[<startKey>:]");
-            state.out.println("                       List rows in the column 
family beginning with <startKey>.");
-            state.out.println("list <cf>[<startKey>:<endKey>]");
-            state.out.println("        List rows in the column family in the 
range from <startKey> to <endKey>.");
-            state.out.println("list ... limit N                                
    Limit the list results to N.");
+            state.out.println("drop keyspace <keyspace>;                       
               Delete a keyspace.");
+            state.out.println("drop column family <cf>;                        
          Delete a column family.");
+            state.out.println("get <cf>['<key>'];                              
          Get a slice of columns.");
+            state.out.println("get <cf>['<key>']['<super>'];                   
      Get a slice of sub columns.");
+            state.out.println("get <cf> where <column> = <value> [and <column> 
> <value> and ...] [limit int];  ");
+            state.out.println("get <cf>['<key>']['<col>'] (as <type>)*;        
              Get a column value.");
+            state.out.println("get <cf>['<key>']['<super>']['<col>'] (as 
<type>)*;       Get a sub column value.");
+            state.out.println("set <cf>['<key>']['<col>'] = <value>;           
                    Set a column.");
+            state.out.println("set <cf>['<key>']['<super>']['<col>'] = 
<value>;                Set a sub column.");
+            state.out.println("del <cf>['<key>'];                              
                   Delete record.");
+            state.out.println("del <cf>['<key>']['<col>'];                     
                   Delete column.");
+            state.out.println("del <cf>['<key>']['<super>']['<col>'];          
               Delete sub column.");
+            state.out.println("count <cf>['<key>'];                            
         Count columns in record.");
+            state.out.println("count <cf>['<key>']['<super>'];                 
 Count columns in a super column.");
+            state.out.println("truncate <column_family>;                       
Truncate specified column family.");
+            state.out.println("assume <column_family> <attribute> as <type>;");
+            state.out.println(" Assume one of the attributes of the given 
column family to match specified type.");
+            state.out.println("list <cf>;                                    
List all rows in the column family.");
+            state.out.println("list <cf>[<startKey>:];");
+            state.out.println("                        List rows in the column 
family beginning with <startKey>.");
+            state.out.println("list <cf>[<startKey>:<endKey>];");
+            state.out.println("         List rows in the column family in the 
range from <startKey> to <endKey>.");
+            state.out.println("list ... limit N;                               
     Limit the list results to N.");
         }
     }
 

Modified: 
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java?rev=1036945&r1=1036944&r2=1036945&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java
 (original)
+++ 
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java
 Fri Nov 19 17:07:53 2010
@@ -35,66 +35,76 @@ public class CliTest extends CleanupHelp
 {
     // please add new statements here so they could be auto-runned by this 
test.
     private String[] statements = {
-        "use TestKeySpace",
-        "create column family CF1 with comparator=UTF8Type and 
column_metadata=[{ column_name:world, validation_class:IntegerType, 
index_type:0, index_name:IdxName }, { column_name:world2, 
validation_class:LongType, index_type:0, index_name:LongIdxName}]",
-        "set CF1[hello][world] = 123848374878933948398384",
-        "get CF1[hello][world]",
-        "set CF1[hello][world2] = 15",
-        "get CF1 where world2 = long(15)",
-        "set CF1['hello'][time_spent_uuid] = 
timeuuid(a8098c1a-f86e-11da-bd1a-00112444be1e)",
-        "create column family CF2 with comparator=IntegerType",
-        "set CF2['key'][98349387493847748398334] = 'some text'",
-        "get CF2['key'][98349387493847748398334]",
-        "set CF2['key'][98349387493] = 'some text other'",
-        "get CF2['key'][98349387493]",
-        "create column family CF3 with comparator=UTF8Type and 
column_metadata=[{column_name:'big world', validation_class:LongType}]",
-        "set CF3['hello']['big world'] = 3748",
-        "get CF3['hello']['big world']",
-        "list CF3",
-        "list CF3[:]",
-        "list CF3[h:]",
-        "list CF3 limit 10",
-        "list CF3[h:] limit 10",
-        "create column family CF4 with comparator=IntegerType and 
column_metadata=[{column_name:9999, validation_class:LongType}]",
-        "set CF4['hello'][9999] = 1234",
-        "get CF4['hello'][9999]",
-        "get CF4['hello'][9999] as Long",
-        "get CF4['hello'][9999] as Bytes",
-        "set CF4['hello'][9999] = Long(1234)",
-        "get CF4['hello'][9999]",
-        "get CF4['hello'][9999] as Long",
-        "del CF4['hello'][9999]",
-        "get CF4['hello'][9999]",
-        "create column family SCF1 with column_type=Super and 
comparator=IntegerType and subcomparator=LongType and 
column_metadata=[{column_name:9999, validation_class:LongType}]",
-        "set SCF1['hello'][1][9999] = 1234",
-        "get SCF1['hello'][1][9999]",
-        "get SCF1['hello'][1][9999] as Long",
-        "get SCF1['hello'][1][9999] as Bytes",
-        "set SCF1['hello'][1][9999] = Long(1234)",
-        "get SCF1['hello'][1][9999]",
-        "get SCF1['hello'][1][9999] as Long",
-        "del SCF1['hello'][1][9999]",
-        "get SCF1['hello'][1][9999]",
-        "set SCF1['hello'][1][9999] = Long(1234)",
-        "del SCF1['hello'][9999]",
-        "get SCF1['hello'][1][9999]",
-        "truncate CF1",
-        "update keyspace TestKeySpace with 
placement_strategy='org.apache.cassandra.locator.LocalStrategy'",
-        "update keyspace TestKeySpace with replication_factor=1 and 
strategy_options=[{DC1:3, DC2:4, DC5:1}]",
-        "assume CF1 comparator as utf8",
-        "assume CF1 sub_comparator as integer",
-        "assume CF1 validator as lexicaluuid",
-        "assume CF1 keys as timeuuid",
-        "create column family CF7",
-        "set CF7[1][timeuuid()] = utf8(test1)",
-        "set CF7[2][lexicaluuid()] = utf8('hello world!')",
-        "set CF7[3][lexicaluuid(550e8400-e29b-41d4-a716-446655440000)] = 
utf8(test2)",
-        "set CF7[key2][timeuuid()] = utf8(test3)",
-        "assume CF7 comparator as lexicaluuid",
-        "assume CF7 keys as utf8",
-        "list CF7",
-        "get CF7[3]",
-        "get CF7[3][lexicaluuid(550e8400-e29b-41d4-a716-446655440000)]"
+        "use TestKeySpace;",
+        "create column family CF1 with comparator=UTF8Type and 
column_metadata=[{ column_name:world, validation_class:IntegerType, 
index_type:0, index_name:IdxName }, { column_name:world2, 
validation_class:LongType, index_type:0, index_name:LongIdxName}];",
+        "set CF1[hello][world] = 123848374878933948398384;",
+        "get CF1[hello][world];",
+        "set CF1[hello][world2] = 15;",
+        "get CF1 where world2 = long(15);",
+        "set CF1['hello'][time_spent_uuid] = 
timeuuid(a8098c1a-f86e-11da-bd1a-00112444be1e);",
+        "create column family CF2 with comparator=IntegerType;",
+        "set CF2['key'][98349387493847748398334] = 'some text';",
+        "get CF2['key'][98349387493847748398334];",
+        "set CF2['key'][98349387493] = 'some text other';",
+        "get CF2['key'][98349387493];",
+        "create column family CF3 with comparator=UTF8Type and 
column_metadata=[{column_name:'big world', validation_class:LongType}];",
+        "set CF3['hello']['big world'] = 3748;",
+        "get CF3['hello']['big world'];",
+        "list CF3;",
+        "list CF3[:];",
+        "list CF3[h:];",
+        "list CF3 limit 10;",
+        "list CF3[h:] limit 10;",
+        "create column family CF4 with comparator=IntegerType and 
column_metadata=[{column_name:9999, validation_class:LongType}];",
+        "set CF4['hello'][9999] = 1234;",
+        "get CF4['hello'][9999];",
+        "get CF4['hello'][9999] as Long;",
+        "get CF4['hello'][9999] as Bytes;",
+        "set CF4['hello'][9999] = Long(1234);",
+        "get CF4['hello'][9999];",
+        "get CF4['hello'][9999] as Long;",
+        "del CF4['hello'][9999];",
+        "get CF4['hello'][9999];",
+        "create column family SCF1 with column_type=Super and 
comparator=IntegerType and subcomparator=LongType and 
column_metadata=[{column_name:9999, validation_class:LongType}];",
+        "set SCF1['hello'][1][9999] = 1234;",
+        "get SCF1['hello'][1][9999];",
+        "get SCF1['hello'][1][9999] as Long;",
+        "get SCF1['hello'][1][9999] as Bytes;",
+        "set SCF1['hello'][1][9999] = Long(1234);",
+        "get SCF1['hello'][1][9999];",
+        "get SCF1['hello'][1][9999] as Long;",
+        "del SCF1['hello'][1][9999];",
+        "get SCF1['hello'][1][9999];",
+        "set SCF1['hello'][1][9999] = Long(1234);",
+        "del SCF1['hello'][9999];",
+        "get SCF1['hello'][1][9999];",
+        "truncate CF1;",
+        "update keyspace TestKeySpace with 
placement_strategy='org.apache.cassandra.locator.LocalStrategy';",
+        "update keyspace TestKeySpace with replication_factor=1 and 
strategy_options=[{DC1:3, DC2:4, DC5:1}];",
+        "assume CF1 comparator as utf8;",
+        "assume CF1 sub_comparator as integer;",
+        "assume CF1 validator as lexicaluuid;",
+        "assume CF1 keys as timeuuid;",
+        "create column family CF7;",
+        "set CF7[1][timeuuid()] = utf8(test1);",
+        "set CF7[2][lexicaluuid()] = utf8('hello world!');",
+        "set CF7[3][lexicaluuid(550e8400-e29b-41d4-a716-446655440000)] = 
utf8(test2);",
+        "set CF7[key2][timeuuid()] = utf8(test3);",
+        "assume CF7 comparator as lexicaluuid;",
+        "assume CF7 keys as utf8;",
+        "list CF7;",
+        "get CF7[3];",
+        "get CF7[3][lexicaluuid(550e8400-e29b-41d4-a716-446655440000)];",
+        "get sCf1['hello'][1][9999];",
+        "set sCf1['hello'][1][9999] = 938;",
+        "list sCf1;",
+        "del SCF1['hello'][1][9999];",
+        "assume sCf1 comparator as utf8;",
+        "create column family CF8;",
+        "drop column family cF8;",
+        "create keyspace TESTIN;",
+        "drop keyspace tesTIN;",
+        "use TestKEYSpace;",
     };
     
     @Test
@@ -115,8 +125,8 @@ public class CliTest extends CleanupHelp
 
         // re-creating keyspace for tests
         // dropping in case it exists e.g. could be left from previous run
-        CliMain.processStatement("drop keyspace TestKeySpace");
-        CliMain.processStatement("create keyspace TestKeySpace");
+        CliMain.processStatement("drop keyspace TestKeySpace;");
+        CliMain.processStatement("create keyspace TestKeySpace;");
 
         for (String statement : statements)
         {


Reply via email to