Skip to content

Commit 372be92

Browse files
authored
Merge pull request #237 from purduesigbots/add-version-to-error
✨Version Display On Error
2 parents d953b0d + fb38e8f commit 372be92

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

pros/cli/click_classes.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from typing import *
33

44
import click.decorators
5+
from click import ClickException
6+
from pros.conductor.project import Project as p
7+
from pros.common.utils import get_version
58

69

710
class PROSFormatted(click.BaseCommand):
@@ -57,7 +60,6 @@ def format_options(self, ctx, formatter):
5760

5861
self.format_commands(ctx, formatter)
5962

60-
6163
class PROSCommand(PROSFormatted, click.Command):
6264
pass
6365

@@ -148,4 +150,16 @@ class PROSRoot(PROSGroup):
148150

149151

150152
class PROSCommandCollection(PROSFormatted, click.CommandCollection):
151-
pass
153+
def invoke(self, *args, **kwargs):
154+
# should change none of the behavior of invoke / ClientException
155+
# should just sit in the pipeline and do a quick echo before
156+
# letting everything else go through.
157+
try:
158+
super(PROSCommandCollection, self).invoke(*args, **kwargs)
159+
except ClickException as e:
160+
click.echo("PROS-CLI Version: {}".format(get_version()))
161+
isProject = p.find_project("")
162+
if (isProject): #check if there is a project
163+
curr_proj = p()
164+
click.echo("PROS-Kernel Version: {}".format(curr_proj.kernel))
165+
raise e

pros/cli/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def main():
4646
ctx_obj = {}
4747
click_handler = pros.common.ui.log.PROSLogHandler(ctx_obj=ctx_obj)
4848
ctx_obj['click_handler'] = click_handler
49-
formatter = pros.common.ui.log.PROSLogFormatter('%(levelname)s - %(name)s:%(funcName)s - %(message)s', ctx_obj)
49+
formatter = pros.common.ui.log.PROSLogFormatter('%(levelname)s - %(name)s:%(funcName)s - %(message)s - pros-cli version:{version}'
50+
.format(version = get_version()), ctx_obj)
5051
click_handler.setFormatter(formatter)
5152
logging.basicConfig(level=logging.WARNING, handlers=[click_handler])
5253
cli.main(prog_name='pros', obj=ctx_obj)

0 commit comments

Comments
 (0)