From 503c590f3a6a85674f4c20f2a8c989e28ecdad11 Mon Sep 17 00:00:00 2001 From: Andre Lobato Date: Fri, 17 Jan 2025 17:12:08 +1300 Subject: [PATCH] Colors for run status --- src/oceanum/cli/prax/project.py | 2 +- src/oceanum/cli/prax/utils.py | 15 +++++++++++++++ src/oceanum/cli/prax/workflows.py | 10 +++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/oceanum/cli/prax/project.py b/src/oceanum/cli/prax/project.py index 6a48e57..98fe96a 100644 --- a/src/oceanum/cli/prax/project.py +++ b/src/oceanum/cli/prax/project.py @@ -91,7 +91,7 @@ def validate_project(ctx: click.Context, specfile: click.Path): def deploy_project( ctx: click.Context, specfile: click.Path, - name: str|None, + name: str|None, org: str|None, user: str|None, wait: bool, diff --git a/src/oceanum/cli/prax/utils.py b/src/oceanum/cli/prax/utils.py index 4d8f74e..d956ab9 100644 --- a/src/oceanum/cli/prax/utils.py +++ b/src/oceanum/cli/prax/utils.py @@ -5,6 +5,21 @@ from .models import ErrorResponse, ProjectSpec, SecretData +def format_run_status(status: str) -> str: + status = status.lower() + if status == 'pending': + return click.style(status.upper(), fg='white') + elif status == 'running': + return click.style(status.upper(), fg='cyan') + elif status == 'succeeded': + return click.style(status.upper(), fg='green') + elif status == 'failed': + return click.style(status.upper(), fg='red') + elif status == 'error': + return click.style(status.upper(), fg='red') + else: + return status + def format_route_status(status: str) -> str: if status == 'online': return click.style(status.upper(), fg='green') diff --git a/src/oceanum/cli/prax/workflows.py b/src/oceanum/cli/prax/workflows.py index f2a2c86..766542a 100644 --- a/src/oceanum/cli/prax/workflows.py +++ b/src/oceanum/cli/prax/workflows.py @@ -17,7 +17,7 @@ project_name_option, name_argument ) -from .utils import echoerr +from .utils import echoerr, format_run_status as frs def parse_parameters(parameters: list[str]|None) -> dict|None: params = {} @@ -36,7 +36,7 @@ def parse_parameters(parameters: list[str]|None) -> dict|None: RenderField( label='Last Run', path='$.last_run', - mod=lambda x: x['status'] if x is not None else 'N/A' + mod=lambda x: frs(x['status']) if x is not None else 'N/A' ), RenderField( label='Started at', @@ -267,6 +267,10 @@ def retry_task(ctx: click.Context, name: str, **filters): @output_format_option @login_required def list_builds(ctx: click.Context, output: str, **filters): + build_fields = LIST_FIELDS + [ + RenderField(label='Source Branch/Tag', path='$.source_ref'), + ] + build_fields.pop(-2) client = PRAXClient(ctx) builds = client.list_builds(**{ k: v for k, v in filters.items() if v is not None @@ -278,7 +282,7 @@ def list_builds(ctx: click.Context, output: str, **filters): echoerr(builds) sys.exit(1) else: - click.echo(Renderer(data=builds, fields=LIST_FIELDS).render(output_format=output)) + click.echo(Renderer(data=builds, fields=build_fields).render(output_format=output)) @describe.command(name='build', help='Describe PRAX Build')