diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2015-06-21 20:42:34 -0700 |
---|---|---|
committer | Amjith Ramanujam <amjith.r@gmail.com> | 2015-06-21 20:42:34 -0700 |
commit | 506db1866996db0af17f5c602556fd882fe60b0e (patch) | |
tree | 498a2fb732f08bb8cc51fd038525c4c142b2dc8b | |
parent | b292a52180b0af05b7e4a0ae30635daf6a623805 (diff) |
Create a new error type for special command not found.
-rw-r--r-- | pgcli/packages/pgspecial/main.py | 10 | ||||
-rw-r--r-- | pgcli/pgexecute.py | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/pgcli/packages/pgspecial/main.py b/pgcli/packages/pgspecial/main.py index 3bee09f9..3fd5161a 100644 --- a/pgcli/packages/pgspecial/main.py +++ b/pgcli/packages/pgspecial/main.py @@ -15,6 +15,10 @@ SpecialCommand = namedtuple('SpecialCommand', COMMANDS = {} @export +class CommandNotFound(Exception): + pass + +@export def parse_special_command(sql): command, _, arg = sql.partition(' ') verbose = '+' in command @@ -47,12 +51,16 @@ def register_special_command(handler, command, syntax, description, @export def execute(cur, sql): command, verbose, pattern = parse_special_command(sql) + + if (command not in COMMANDS) and (command.lower() not in COMMANDS): + raise CommandNotFound + try: special_cmd = COMMANDS[command] except KeyError: special_cmd = COMMANDS[command.lower()] if special_cmd.case_sensitive: - raise KeyError('Command not found: %s' % command) + raise CommandNotFound('Command not found: %s' % command) if special_cmd.arg_type == NO_QUERY: return special_cmd.handler() diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index ed4290da..535d2c5a 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -208,7 +208,7 @@ class PGExecute(object): cur = self.conn.cursor() for result in special.execute(cur, sql): yield result - except KeyError: # Regular SQL + except special.CommandNotFound: # Regular SQL yield self.execute_normal_sql(sql) def execute_normal_sql(self, split_sql): |