diff --git a/griffon/commands/queries.py b/griffon/commands/queries.py index 78f2710..9b9186f 100644 --- a/griffon/commands/queries.py +++ b/griffon/commands/queries.py @@ -40,6 +40,7 @@ generate_entity_report, generate_license_report, ) +from griffon.helpers import Style from griffon.output import ( console, cprint, @@ -188,12 +189,12 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): # @click.option( # "--cve-id", # "cve_id", -# help="Attach affects to this (\033[1mCVE-ID\033[0m).", +# help=f"Attach affects to this {Style.BOLD}CVE-ID{Style.RESET}.", # ) @click.option( "--sfm2-flaw-id", "sfm2_flaw_id", - help="Attach affects to this (\033[1msfm2 flaw id\033[0m).", + help=f"Attach affects to this {Style.BOLD}sfm2 flaw id{Style.RESET}.", ) @click.option( "--flaw-mode", @@ -207,28 +208,28 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): "search_latest", is_flag=True, default=False, - help="Search root Components (\033[1menabled by default\033[0m).", + help=f"Search root Components {Style.BOLD}(enabled by default){Style.RESET}.", ) @click.option( "--search-provides", "search_provides", is_flag=True, default=False, - help="Search root Components by provides children(\033[1menabled by default\033[0m).", + help=f"Search root Components by provides children {Style.BOLD}(enabled by default){Style.RESET}.", ) @click.option( "--search-upstreams", "search_upstreams", is_flag=True, default=False, - help="Search root Components by upstreams children (\033[1menabled by default\033[0m).", + help=f"Search root Components by upstreams children {Style.BOLD}(enabled by default){Style.RESET}.", ) @click.option( "--search-related-url", "search_related_url", is_flag=True, default=False, - help="Search related url (\033[1menabled by default\033[0m).", + help=f"Search related url {Style.BOLD}(enabled by default){Style.RESET}.", ) @click.option( "--filter-rh-naming", @@ -357,7 +358,7 @@ def get_product_contain_component( if not purl and not component_name: click.echo(ctx.get_help()) click.echo("") - click.echo("\033[1mMust supply Component name or --purl.\033[0m") + click.echo(f"{Style.BOLD}Must supply Component name or --purl.{Style.RESET}") exit(0) if ( @@ -576,7 +577,8 @@ def get_product_contain_component( else: console.print("Flaw is not missing any affect entries") - ctx.exit() + # ctx.exit() + return cprint(q, ctx=ctx) diff --git a/griffon/helpers.py b/griffon/helpers.py index f1822b6..c006976 100644 --- a/griffon/helpers.py +++ b/griffon/helpers.py @@ -2,6 +2,7 @@ Helpers for direct usage or debbuging """ import json +from enum import Enum from typing import Callable, Optional, Type, Union from component_registry_bindings.bindings.python_client.types import ( @@ -61,3 +62,47 @@ def debug_data_load( else: data = json_data return data + + +class Color(Enum): + """ + Helper enum for text color formatting for anything which + cannot be rendered using rich + """ + + BLACK = "\033[30m" + RED = "\033[31m" + GREEN = "\033[32m" + YELLOW = "\033[33m" + BLUE = "\033[34m" + MAGENTA = "\033[35m" + CYAN = "\033[36m" + WHITE = "\033[37m" + GREY = "\033[90m" + BRIGHT_RED = "\033[91m" + BRIGHT_GREEN = "\033[92m" + BRIGHT_YELLOW = "\033[93m" + BRIGHT_BLUE = "\033[94m" + BRIGHT_MAGENTA = "\033[95m" + BRIGHT_CYAN = "\033[96m" + BRIGHT_WHITE = "\033[97m" + RESET = "\033[0m" # Reset to default color and style + + def __str__(self): + return str(self.value) + + +class Style(Enum): + """ + Helper enum for text style formatting for anything which + cannot be rendered using rich + """ + + BOLD = "\033[1m" + ITALIC = "\033[3m" + UNDERLINE = "\033[4m" + STRIKE = "\033[9m" + RESET = "\033[0m" # Reset to default style + + def __str__(self): + return str(self.value)