From 601b7e0e438dad002c80adbf20edd6c16691b425 Mon Sep 17 00:00:00 2001 From: Karel Blavka Date: Thu, 28 Apr 2022 11:14:32 +0200 Subject: [PATCH] Update module version --- src/hardwario/common/cli.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hardwario/common/cli.py b/src/hardwario/common/cli.py index 9429140..129ce44 100644 --- a/src/hardwario/common/cli.py +++ b/src/hardwario/common/cli.py @@ -14,16 +14,18 @@ def version_cb(ctx, param, value): + if not value or ctx.resilient_parsing: + return modules = ctx.obj['modules'] for name in sorted(modules): click.echo(f'{name} {modules[name]}') ctx.exit() -@ click.group() -@ click.option('--log-level', type=click.Choice(['debug', 'info', 'success', 'warning', 'error', 'critical']), - help='Log level to stderr', default="critical", show_default=True) -@ click.option('--version', is_flag=True, expose_value=False, help='Show the version and exit.', callback=version_cb) +@click.group() +@click.option('--log-level', type=click.Choice(['debug', 'info', 'success', 'warning', 'error', 'critical']), + help='Log level to stderr', default="critical", show_default=True) +@click.option('--version', is_flag=True, expose_value=False, help='Show the version and exit.', callback=version_cb) def cli_root(log_level): '''HARDWARIO Command Line Tool.''' logger.add(sys.stderr, level=log_level.upper()) @@ -56,7 +58,7 @@ def main(): module = importlib.import_module(name) # modules[name] = '?' if hasattr(module, '__version__'): - logger.debug('Module: {} version {}', name, module.__version__) + logger.debug('Module: {} Version {}', name, module.__version__) modules[name] = module.__version__ if hasattr(module, 'cli'): cli_root.add_command(module.cli.cli) @@ -67,7 +69,8 @@ def main(): pass try: - cli_root(obj={'modules': modules}, auto_envvar_prefix='HARDWARIO') + with logger.catch(reraise=True, exclude=KeyboardInterrupt): + cli_root(obj={'modules': modules}, auto_envvar_prefix='HARDWARIO') except KeyboardInterrupt: pass except Exception as e: