Changes to end handling.
This commit is contained in:
@@ -88,6 +88,13 @@ def cli(ctx, conf, server, agwpe, port, callsign):
|
|||||||
ctx.obj['bbs'] = server
|
ctx.obj['bbs'] = server
|
||||||
ctx.obj['db'] = db
|
ctx.obj['db'] = db
|
||||||
|
|
||||||
|
@cli.result_callback()
|
||||||
|
@click.pass_context
|
||||||
|
def cli_callback(result, ctx):
|
||||||
|
ctx.obj['client'].stop()
|
||||||
|
sys.exit(result)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument('username', required=False, default='')
|
@click.argument('username', required=False, default='')
|
||||||
@click.option('--list-users', '-l', is_flag=True, default=False, help="If set, downloads list of all users.")
|
@click.option('--list-users', '-l', is_flag=True, default=False, help="If set, downloads list of all users.")
|
||||||
@@ -100,11 +107,11 @@ def user(ctx, list_users, output_format, username):
|
|||||||
# validate args
|
# validate args
|
||||||
if list_users and (username.strip() != ""):
|
if list_users and (username.strip() != ""):
|
||||||
click.echo("Can't specify a username while listing all users.", err=True)
|
click.echo("Can't specify a username while listing all users.", err=True)
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
if not list_users and (username.strip() == ""):
|
if not list_users and (username.strip() == ""):
|
||||||
click.echo("Must provide either a username or --list-users flag.", err=True)
|
click.echo("Must provide either a username or --list-users flag.", err=True)
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
output_objects = []
|
output_objects = []
|
||||||
try:
|
try:
|
||||||
@@ -114,9 +121,12 @@ def user(ctx, list_users, output_format, username):
|
|||||||
output_objects.append(users.get_user_by_username(client, ctx.obj['bbs'], username))
|
output_objects.append(users.get_user_by_username(client, ctx.obj['bbs'], username))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
click.echo(str(e), err=True)
|
click.echo(str(e), err=True)
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
finally:
|
||||||
|
client.stop()
|
||||||
|
|
||||||
click.echo(format_list_dicts([x.pretty_dict() for x in output_objects], output_format=output_format.lower()))
|
click.echo(format_list_dicts([x.pretty_dict() for x in output_objects], output_format=output_format.lower()))
|
||||||
|
return 1
|
||||||
|
|
||||||
cli.add_command(user)
|
cli.add_command(user)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user