1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-10-04 01:08:51 +03:00

Add exception handling.

This commit is contained in:
Amjith Ramanujam 2014-11-23 00:09:00 -08:00
parent da327d4742
commit ab8d34df84
2 changed files with 18 additions and 7 deletions

10
TODO
View File

@ -1,4 +1,8 @@
* [ ] Translate the commands to pg backend.
* [ ] Add options to read the host, user, passwd etc.
* [ ] Add auto-completion based on the tables, columns names.
* [X] Translate the commands to pg backend.
* [X] Add options to read the host, user, passwd etc.
* [ ] Add the back-slash commands.
* [X] Deal with errors that happen at connection (password, host etc).
* [X] Deal with errors that happen during sql execution.
* [ ] Add auto-completion based on the tables, columns names.
* [ ] Figure out how to deal with transactions.
* [ ] Add a lot more SQL keywords to auto-completion.

View File

@ -19,12 +19,15 @@ from pygments.lexers import SqlLexer
@click.option('-h', '--host', default='localhost')
@click.option('-p', '--port', default=5432)
@click.option('-U', '--user', prompt=True, envvar='USER')
@click.password_option('-P', '--password', default='',
@click.password_option('-W', '--password', default='',
confirmation_prompt=False)
@click.argument('database', envvar='USER')
def pgcli(database, user, password, host, port):
print('database: %s host: %s user: %s password: %s' % (database, host, user, password))
pgexecute = PGExecute(database, user, password, host, port)
try:
pgexecute = PGExecute(database, user, password, host, port)
except Exception as e:
click.secho(e.message, err=True, fg='red')
exit(1)
layout = Layout(before_input=DefaultPrompt('%s> ' % database),
menus=[CompletionsMenu()],
lexer=SqlLexer)
@ -34,6 +37,10 @@ def pgcli(database, user, password, host, port):
try:
while True:
document = cli.read_input(on_exit=AbortAction.RAISE_EXCEPTION)
print (pgexecute.run(document.text))
try:
print(pgexecute.run(document.text))
except Exception as e:
click.secho("Does not compute!", fg='red')
click.secho(e.message, err=True, fg='red')
except Exit:
print ('GoodBye!')