Skip to content

Commit

Permalink
Update module version
Browse files Browse the repository at this point in the history
  • Loading branch information
blavka committed Apr 28, 2022
1 parent 8f38454 commit 601b7e0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/hardwario/common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 601b7e0

Please sign in to comment.