Skip to content

Commit

Permalink
Merge pull request #237 from purduesigbots/add-version-to-error
Browse files Browse the repository at this point in the history
✨Version Display On Error
  • Loading branch information
AlexHunton2 committed Oct 18, 2022
2 parents d953b0d + fb38e8f commit 372be92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 16 additions & 2 deletions pros/cli/click_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -57,7 +60,6 @@ def format_options(self, ctx, formatter):

self.format_commands(ctx, formatter)


class PROSCommand(PROSFormatted, click.Command):
pass

Expand Down Expand Up @@ -148,4 +150,16 @@ class PROSRoot(PROSGroup):


class PROSCommandCollection(PROSFormatted, click.CommandCollection):
pass
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
3 changes: 2 additions & 1 deletion pros/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 372be92

Please sign in to comment.