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:
parent
da327d4742
commit
ab8d34df84
10
TODO
10
TODO
@ -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.
|
||||
|
15
pgcli.py
15
pgcli.py
@ -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!')
|
||||
|
Loading…
Reference in New Issue
Block a user