Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Version Display On Error #237

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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