Updated Branches: refs/heads/cassandra-1.2 4cd813632 -> df6983bba
cqlsh: Add username autocompletion patch by Aleksey Yeschenko; reviewed by Brandon Williams for CASSANDRA-5231 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/df6983bb Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/df6983bb Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/df6983bb Branch: refs/heads/cassandra-1.2 Commit: df6983bbad7f004aac52cfe78c5fb41e8a3871bc Parents: 4cd8136 Author: Aleksey Yeschenko <alek...@apache.org> Authored: Tue Feb 19 07:21:08 2013 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Tue Feb 19 07:21:08 2013 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + pylib/cqlshlib/cql3handling.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/df6983bb/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index ad8c3f2..a543ac1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -25,6 +25,7 @@ * Fix timestamp-based tomstone removal logic (CASSANDRA-5248) * cli: Add JMX authentication support (CASSANDRA-5080) * Fix forceFlush behavior (CASSANDRA-5241) + * cqlsh: Add username autocompletion (CASSANDRA-5231) 1.2.1 http://git-wip-us.apache.org/repos/asf/cassandra/blob/df6983bb/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index def573e..00e2d0f 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -1256,7 +1256,7 @@ syntax_rules += r''' ''' syntax_rules += r''' -<username> ::= user=( <identifier> | <stringLiteral> ) +<username> ::= name=( <identifier> | <stringLiteral> ) ; <createUserStatement> ::= "CREATE" "USER" <username> @@ -1308,13 +1308,20 @@ syntax_rules += r''' ; ''' +@completer_for('username', 'name') +def username_name_completer(ctxt, cass): + def maybe_quote(name): + if CqlRuleSet.is_valid_cql3_name(name): + return name + return "'%s'" % name + + # disable completion for CREATE USER. + if ctxt.matched[0][0] == 'K_CREATE': + return [Hint('<username>')] -@completer_for('username', 'user') -def username_user_completer(ctxt, cass): - # TODO: implement user autocompletion for grant/revoke/list/drop user/alter user - # with I could see a way to do this usefully, but I don't. I don't know - # how any Authorities other than AllowAllAuthorizer work :/ - return [Hint('<username>')] + cursor = cass.conn.cursor() + cursor.execute("LIST USERS") + return [maybe_quote(row[0].replace("'", "''")) for row in cursor.fetchall()] # END SYNTAX/COMPLETION RULE DEFINITIONS