From cdcb98e438df407394f95eb11a849cc5a2b066b7 Mon Sep 17 00:00:00 2001 From: Hemna Date: Mon, 8 Nov 2021 12:18:23 -0500 Subject: [PATCH] Cleaned up some verbose output & colorized output Some commands now have some color if the shell detects it supports it. --- aprsd/aprsd.py | 15 ++++++--------- aprsd/cli_helper.py | 36 ------------------------------------ 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/aprsd/aprsd.py b/aprsd/aprsd.py index 6161941..1556a01 100644 --- a/aprsd/aprsd.py +++ b/aprsd/aprsd.py @@ -34,7 +34,7 @@ import click_completion import aprsd from aprsd import cli_helper from aprsd import config as aprsd_config -from aprsd import log, messaging, packets, stats, threads, utils +from aprsd import messaging, packets, stats, threads, utils # setup the global logger @@ -65,6 +65,7 @@ def cli(ctx): def main(): # First import all the possible commands for the CLI + # The commands themselves live in the cmds directory from .cmds import ( # noqa completion, dev, healthcheck, listen, send_message, server, ) @@ -99,16 +100,11 @@ def signal_handler(sig, frame): @cli_helper.process_standard_options def check_version(ctx): """Check this version against the latest in pypi.org.""" - config_file = ctx.obj["config_file"] - loglevel = ctx.obj["loglevel"] - config = aprsd_config.parse_config(config_file) - - log.setup_logging(config, loglevel, False) level, msg = utils._check_version() if level: - LOG.warning(msg) + click.secho(msg, fg="yellow") else: - LOG.info(msg) + click.secho(msg, fg="green") @cli.command() @@ -122,7 +118,8 @@ def sample_config(ctx): @click.pass_context def version(ctx): """Show the APRSD version.""" - click.echo(f"APRSD Version : {aprsd.__version__}") + click.echo(click.style("APRSD Version : ", fg="white"), nl=False) + click.secho(f"{aprsd.__version__}", fg="yellow", bold=True) if __name__ == "__main__": diff --git a/aprsd/cli_helper.py b/aprsd/cli_helper.py index c20e732..ab8bf7e 100644 --- a/aprsd/cli_helper.py +++ b/aprsd/cli_helper.py @@ -48,8 +48,6 @@ def add_options(options): def process_standard_options(f: F) -> F: def new_func(*args, **kwargs): - print(f"ARGS {args}") - print(f"KWARGS {kwargs}") ctx = args[0] ctx.ensure_object(dict) ctx.obj["loglevel"] = kwargs["loglevel"] @@ -67,37 +65,3 @@ def process_standard_options(f: F) -> F: return f(*args, **kwargs) return update_wrapper(t.cast(F, new_func), f) - - -class AliasedGroup(click.Group): - def command(self, *args, **kwargs): - """A shortcut decorator for declaring and attaching a command to - the group. This takes the same arguments as :func:`command` but - immediately registers the created command with this instance by - calling into :meth:`add_command`. - Copied from `click` and extended for `aliases`. - """ - def decorator(f): - aliases = kwargs.pop("aliases", []) - cmd = click.decorators.command(*args, **kwargs)(f) - self.add_command(cmd) - for alias in aliases: - self.add_command(cmd, name=alias) - return cmd - return decorator - - def group(self, *args, **kwargs): - """A shortcut decorator for declaring and attaching a group to - the group. This takes the same arguments as :func:`group` but - immediately registers the created command with this instance by - calling into :meth:`add_command`. - Copied from `click` and extended for `aliases`. - """ - def decorator(f): - aliases = kwargs.pop("aliases", []) - cmd = click.decorators.group(*args, **kwargs)(f) - self.add_command(cmd) - for alias in aliases: - self.add_command(cmd, name=alias) - return cmd - return decorator