Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB739E2A0 for ; Tue, 19 Feb 2013 04:27:12 +0000 (UTC) Received: (qmail 28142 invoked by uid 500); 19 Feb 2013 04:27:12 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 28099 invoked by uid 500); 19 Feb 2013 04:27:12 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 28074 invoked by uid 99); 19 Feb 2013 04:27:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 04:27:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C6EA982C371; Tue, 19 Feb 2013 04:27:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aleksey@apache.org To: commits@cassandra.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: cqlsh: Add username autocompletion Message-Id: <20130219042711.C6EA982C371@tyr.zones.apache.org> Date: Tue, 19 Feb 2013 04:27:11 +0000 (UTC) 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/trunk Commit: df6983bbad7f004aac52cfe78c5fb41e8a3871bc Parents: 4cd8136 Author: Aleksey Yeschenko Authored: Tue Feb 19 07:21:08 2013 +0300 Committer: Aleksey Yeschenko 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''' - ::= user=( | ) + ::= name=( | ) ; ::= "CREATE" "USER" @@ -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('')] -@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('')] + cursor = cass.conn.cursor() + cursor.execute("LIST USERS") + return [maybe_quote(row[0].replace("'", "''")) for row in cursor.fetchall()] # END SYNTAX/COMPLETION RULE DEFINITIONS