From 1fd832ddffe83a07f82939bd9e5787a61aeba1ef Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 18 Apr 2012 16:55:01 +0300 Subject: [PATCH] psql: Add tab completion for CREATE/ALTER ROLE name WITH Previously, the use of the optional key word WITH was not supported. Josh Kupershmidt --- src/bin/psql/tab-complete.c | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 00df2c6197..2864693158 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1024,11 +1024,28 @@ psql_completion(char *text, int start, int end) "ENCRYPTED", "INHERIT", "LOGIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NOINHERIT", "NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "RENAME TO", "REPLICATION", "RESET", "SET", - "SUPERUSER", "UNENCRYPTED", "VALID UNTIL", NULL}; + "SUPERUSER", "UNENCRYPTED", "VALID UNTIL", "WITH", NULL}; COMPLETE_WITH_LIST(list_ALTERUSER); } + /* ALTER USER,ROLE WITH */ + else if ((pg_strcasecmp(prev4_wd, "ALTER") == 0 && + (pg_strcasecmp(prev3_wd, "USER") == 0 || + pg_strcasecmp(prev3_wd, "ROLE") == 0) && + pg_strcasecmp(prev_wd, "WITH") == 0)) + { + /* Similar to the above, but don't complete "WITH" again. */ + static const char *const list_ALTERUSER_WITH[] = + {"CONNECTION LIMIT", "CREATEDB", "CREATEROLE", "CREATEUSER", + "ENCRYPTED", "INHERIT", "LOGIN", "NOCREATEDB", "NOCREATEROLE", + "NOCREATEUSER", "NOINHERIT", "NOLOGIN", "NOREPLICATION", + "NOSUPERUSER", "RENAME TO", "REPLICATION", "RESET", "SET", + "SUPERUSER", "UNENCRYPTED", "VALID UNTIL", NULL}; + + COMPLETE_WITH_LIST(list_ALTERUSER_WITH); + } + /* complete ALTER USER,ROLE ENCRYPTED,UNENCRYPTED with PASSWORD */ else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 && (pg_strcasecmp(prev3_wd, "ROLE") == 0 || pg_strcasecmp(prev3_wd, "USER") == 0) && @@ -1947,7 +1964,7 @@ psql_completion(char *text, int start, int end) prev2_wd[0] != '\0') COMPLETE_WITH_CONST("PROCEDURE"); -/* CREATE ROLE,USER,GROUP */ +/* CREATE ROLE,USER,GROUP */ else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 && !(pg_strcasecmp(prev2_wd, "USER") == 0 && pg_strcasecmp(prev_wd, "MAPPING") == 0) && (pg_strcasecmp(prev2_wd, "ROLE") == 0 || @@ -1958,11 +1975,29 @@ psql_completion(char *text, int start, int end) "ENCRYPTED", "IN", "INHERIT", "LOGIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NOINHERIT", "NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "REPLICATION", "ROLE", - "SUPERUSER", "SYSID", "UNENCRYPTED", "VALID UNTIL", NULL}; + "SUPERUSER", "SYSID", "UNENCRYPTED", "VALID UNTIL", "WITH", NULL}; COMPLETE_WITH_LIST(list_CREATEROLE); } +/* CREATE ROLE,USER,GROUP WITH */ + else if ((pg_strcasecmp(prev4_wd, "CREATE") == 0 && + (pg_strcasecmp(prev3_wd, "ROLE") == 0 || + pg_strcasecmp(prev3_wd, "GROUP") == 0 || + pg_strcasecmp(prev3_wd, "USER") == 0) && + pg_strcasecmp(prev_wd, "WITH") == 0)) + { + /* Similar to the above, but don't complete "WITH" again. */ + static const char *const list_CREATEROLE_WITH[] = + {"ADMIN", "CONNECTION LIMIT", "CREATEDB", "CREATEROLE", "CREATEUSER", + "ENCRYPTED", "IN", "INHERIT", "LOGIN", "NOCREATEDB", + "NOCREATEROLE", "NOCREATEUSER", "NOINHERIT", "NOLOGIN", + "NOREPLICATION", "NOSUPERUSER", "REPLICATION", "ROLE", + "SUPERUSER", "SYSID", "UNENCRYPTED", "VALID UNTIL", NULL}; + + COMPLETE_WITH_LIST(list_CREATEROLE_WITH); + } + /* * complete CREATE ROLE,USER,GROUP ENCRYPTED,UNENCRYPTED with * PASSWORD -- 2.40.0