1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-04-09 21:18:37 -04:00

Cleaned up some verbose output & colorized output

Some commands now have some color if the shell detects it supports it.
This commit is contained in:
Hemna 2021-11-08 12:18:23 -05:00
parent 89727e2b8e
commit cdcb98e438
2 changed files with 6 additions and 45 deletions

View File

@ -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__":

View File

@ -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