From 8dd9eec7bda93c73a878e2533746aa1697138fca Mon Sep 17 00:00:00 2001 From: AlexHunton2 Date: Sat, 17 Sep 2022 18:26:57 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Version=20Display=20On=20Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pros/cli/click_classes.py | 18 ++++++++++++++++-- pros/cli/main.py | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index b24eb1ac..cb5a82c0 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -2,6 +2,9 @@ from typing import * import click.decorators +from click import ClickException +from pros.conductor.project import Project as p +from pros.common.utils import get_version class PROSFormatted(click.BaseCommand): @@ -57,7 +60,6 @@ def format_options(self, ctx, formatter): self.format_commands(ctx, formatter) - class PROSCommand(PROSFormatted, click.Command): pass @@ -148,4 +150,16 @@ class PROSRoot(PROSGroup): class PROSCommandCollection(PROSFormatted, click.CommandCollection): - pass \ No newline at end of file + def invoke(self, *args, **kwargs): + # should change none of the behavior of invoke / ClientException + # should just sit in the pipeline and do a quick echo before + # letting everything else go through. + try: + super(PROSCommandCollection, self).invoke(*args, **kwargs) + except ClickException as e: + click.echo("PROS-CLI Version: {}".format(get_version())) + isProject = p.find_project("") + if (isProject): #check if there is a project + curr_proj = p() + click.echo("PROS-Kernel Version: {}".format(curr_proj.kernel)) + raise e \ No newline at end of file diff --git a/pros/cli/main.py b/pros/cli/main.py index d35c4aef..cbd8ec51 100644 --- a/pros/cli/main.py +++ b/pros/cli/main.py @@ -46,7 +46,8 @@ def main(): ctx_obj = {} click_handler = pros.common.ui.log.PROSLogHandler(ctx_obj=ctx_obj) ctx_obj['click_handler'] = click_handler - formatter = pros.common.ui.log.PROSLogFormatter('%(levelname)s - %(name)s:%(funcName)s - %(message)s', ctx_obj) + formatter = pros.common.ui.log.PROSLogFormatter('%(levelname)s - %(name)s:%(funcName)s - %(message)s - pros-cli version:{version}' + .format(version = get_version()), ctx_obj) click_handler.setFormatter(formatter) logging.basicConfig(level=logging.WARNING, handlers=[click_handler]) cli.main(prog_name='pros', obj=ctx_obj)