diff --git a/CHANGES.txt b/CHANGES.txt index ad8c3f2c68..a543ac16e0 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 diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index def573e616..00e2d0f03c 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 -@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('')] + # disable completion for CREATE USER. + if ctxt.matched[0][0] == 'K_CREATE': + 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