diff options
author | Masahiko Sawada <msawada@postgresql.org> | 2024-04-08 12:15:10 +0900 |
---|---|---|
committer | Masahiko Sawada <msawada@postgresql.org> | 2024-04-08 12:15:10 +0900 |
commit | 304b6b1a6b7116bae30ea24119f04474eba7f0ed (patch) | |
tree | 081dde8446d53087e943c50cf9a194759dd6a26d | |
parent | 3b08133cd13c4ac985a94222280160282ba35838 (diff) | |
download | postgresql-304b6b1a6b7116bae30ea24119f04474eba7f0ed.tar.gz postgresql-304b6b1a6b7116bae30ea24119f04474eba7f0ed.zip |
Add more tab completion support for ALTER DEFAULT PRIVILEGES in psql.
This adds tab completion of "GRANT" and "REVOKE [GRANT OPTION FOR]"
for ALTER DEFAULT PRIVILEGES, and adds "WITH GRANT OPTION" for
ALTER DEFAULT PRIVILEGES ... GRANT ... TO role.
Author: Vignesh C, with cosmetic adjustments by me
Reviewed-by: Shubham Khanna, Masahiko Sawada
Discussion: https://postgr.es/m/CALDaNm1aEdJb-QJi%3DGWStkfj_%2BEDUK_VtDkn%2BTjQ2z7HyU0MBw%40mail.gmail.com
-rw-r--r-- | src/bin/psql/tab-complete.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 82eb3955abf..6fee3160f02 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2147,7 +2147,7 @@ psql_completion(const char *text, int start, int end) /* ALTER DEFAULT PRIVILEGES */ else if (Matches("ALTER", "DEFAULT", "PRIVILEGES")) - COMPLETE_WITH("FOR ROLE", "IN SCHEMA"); + COMPLETE_WITH("FOR", "GRANT", "IN SCHEMA", "REVOKE"); /* ALTER DEFAULT PRIVILEGES FOR */ else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "FOR")) COMPLETE_WITH("ROLE"); @@ -3949,9 +3949,18 @@ psql_completion(const char *text, int start, int end) * privileges (can't grant roles) */ if (HeadMatches("ALTER", "DEFAULT", "PRIVILEGES")) - COMPLETE_WITH("SELECT", "INSERT", "UPDATE", - "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", - "CREATE", "EXECUTE", "USAGE", "MAINTAIN", "ALL"); + { + if (TailMatches("GRANT") || + TailMatches("REVOKE", "GRANT", "OPTION", "FOR")) + COMPLETE_WITH("SELECT", "INSERT", "UPDATE", + "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", + "CREATE", "EXECUTE", "USAGE", "MAINTAIN", "ALL"); + else if (TailMatches("REVOKE")) + COMPLETE_WITH("SELECT", "INSERT", "UPDATE", + "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", + "CREATE", "EXECUTE", "USAGE", "MAINTAIN", "ALL", + "GRANT OPTION FOR"); + } else if (TailMatches("GRANT")) COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, Privilege_options_of_grant_and_revoke); @@ -4133,6 +4142,9 @@ psql_completion(const char *text, int start, int end) else if (HeadMatches("ALTER", "DEFAULT", "PRIVILEGES") && TailMatches("TO|FROM")) COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, Keywords_for_list_of_grant_roles); + /* Offer WITH GRANT OPTION after that */ + else if (HeadMatches("ALTER", "DEFAULT", "PRIVILEGES") && TailMatches("TO", MatchAny)) + COMPLETE_WITH("WITH GRANT OPTION"); /* Complete "GRANT/REVOKE ... ON * *" with TO/FROM */ else if (HeadMatches("GRANT") && TailMatches("ON", MatchAny, MatchAny)) COMPLETE_WITH("TO"); |