cqlsh: Add username autocompletion

patch by Aleksey Yeschenko; reviewed by Brandon Williams for
CASSANDRA-5231
This commit is contained in:
Aleksey Yeschenko 2013-02-19 07:21:08 +03:00
parent 4cd813632d
commit df6983bbad
2 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -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
@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>')]
# disable completion for CREATE USER.
if ctxt.matched[0][0] == 'K_CREATE':
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