From a5ddf508826055df0257148381fb2dcf9fcd6150 Mon Sep 17 00:00:00 2001 From: Jean-Marc Fontaine Date: Fri, 5 Apr 2024 22:00:31 +0000 Subject: [PATCH] Colorize CLI commands usage --- poetry.lock | 19 ++++++++++++++++++- pyproject.toml | 1 + spacemk/cli.py | 8 +++++++- spacemk/commands/audit.py | 8 +++++++- spacemk/commands/create_module_versions.py | 8 +++++++- spacemk/commands/export.py | 8 +++++++- spacemk/commands/generate.py | 8 +++++++- spacemk/commands/set_sensitive_env_vars.py | 8 +++++++- .../commands/set_tf_vars_with_invalid_name.py | 8 +++++++- 9 files changed, 68 insertions(+), 8 deletions(-) diff --git a/poetry.lock b/poetry.lock index a4cfb20..735736d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -167,6 +167,23 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} +[[package]] +name = "click-help-colors" +version = "0.9.4" +description = "Colorization of help messages in Click" +optional = false +python-versions = "*" +files = [ + {file = "click-help-colors-0.9.4.tar.gz", hash = "sha256:f4cabe52cf550299b8888f4f2ee4c5f359ac27e33bcfe4d61db47785a5cc936c"}, + {file = "click_help_colors-0.9.4-py3-none-any.whl", hash = "sha256:b33c5803eeaeb084393b1ab5899dc5476c7196b87a18713045afe76f840b42db"}, +] + +[package.dependencies] +click = ">=7.0,<9" + +[package.extras] +dev = ["mypy", "pytest"] + [[package]] name = "clickloader" version = "0.2.0" @@ -1556,4 +1573,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "97e7de0f28f9b8f5b79fd5a6b0b8dd08e6cadd96859bcc083c503c1613b47093" +content-hash = "15f407e3cf7ad37fc214bf9c9988b5ff8cb8d37ee8ab627fcbee915219b98c9c" diff --git a/pyproject.toml b/pyproject.toml index bd00e9a..c98a696 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ requests-toolbelt = "1.0.0" requests = "2.31.0" rich = "13.7.1" xlsxwriter = "3.2.0" +click-help-colors = "^0.9.4" [tool.poetry.group.dev.dependencies] coverage = { extras = ["toml"], version = "^7.4.4" } diff --git a/spacemk/cli.py b/spacemk/cli.py index eded1ce..617e5c2 100755 --- a/spacemk/cli.py +++ b/spacemk/cli.py @@ -5,6 +5,7 @@ import ccl import click from benedict import benedict +from click_help_colors import HelpColorsGroup from dotenv import load_dotenv from envyaml import EnvYAML from icecream import ic @@ -14,7 +15,12 @@ debug_enabled = False -@click.group(help="Helper to move from various tools to Spacelift.") +@click.group( + cls=HelpColorsGroup, + help="Helper to move from various tools to Spacelift.", + help_headers_color="yellow", + help_options_color="green", +) @click.option( "--config", default="config.yml", diff --git a/spacemk/commands/audit.py b/spacemk/commands/audit.py index 848a7c4..6f78b0a 100644 --- a/spacemk/commands/audit.py +++ b/spacemk/commands/audit.py @@ -1,10 +1,16 @@ import click from click.decorators import pass_meta_key +from click_help_colors import HelpColorsCommand from spacemk.exporters import load_exporter -@click.command(help="Audit the source vendor setup.") +@click.command( + cls=HelpColorsCommand, + help="Audit the source vendor setup.", + help_headers_color="yellow", + help_options_color="green", +) @pass_meta_key("config") def audit(config): exporter = load_exporter(config=config.get("exporter", {})) diff --git a/spacemk/commands/create_module_versions.py b/spacemk/commands/create_module_versions.py index b9388f3..9699ee2 100644 --- a/spacemk/commands/create_module_versions.py +++ b/spacemk/commands/create_module_versions.py @@ -2,6 +2,7 @@ import click import requests +from click_help_colors import HelpColorsCommand from requests_toolbelt.utils import dump as request_dump from spacemk import load_normalized_data @@ -31,7 +32,12 @@ def _get_repository_tags(endpoint: str, github_api_token: str, namespace: str, r return data -@click.command(help="Create module versions.") +@click.command( + cls=HelpColorsCommand, + help="Create module versions.", + help_headers_color="yellow", + help_options_color="green", +) @click.decorators.pass_meta_key("config") def create_module_versions(config): data = load_normalized_data() diff --git a/spacemk/commands/export.py b/spacemk/commands/export.py index 21b3043..a3bca07 100644 --- a/spacemk/commands/export.py +++ b/spacemk/commands/export.py @@ -1,10 +1,16 @@ import click from click.decorators import pass_meta_key +from click_help_colors import HelpColorsCommand from spacemk.exporters import load_exporter -@click.command(help="Export information from the source vendor.") +@click.command( + cls=HelpColorsCommand, + help="Export information from the source vendor.", + help_headers_color="yellow", + help_options_color="green", +) @pass_meta_key("config") def export(config): exporter = load_exporter(config=config.get("exporter", {})) diff --git a/spacemk/commands/generate.py b/spacemk/commands/generate.py index 45fd5f7..3472e38 100644 --- a/spacemk/commands/generate.py +++ b/spacemk/commands/generate.py @@ -1,9 +1,15 @@ import click +from click_help_colors import HelpColorsCommand from spacemk.generator import Generator -@click.command(help="Generate Terraform code to manage Spacelift entities.") +@click.command( + cls=HelpColorsCommand, + help="Generate Terraform code to manage Spacelift entities.", + help_headers_color="yellow", + help_options_color="green", +) def generate(): generator = Generator() generator.generate() diff --git a/spacemk/commands/set_sensitive_env_vars.py b/spacemk/commands/set_sensitive_env_vars.py index dd60d57..91fa402 100644 --- a/spacemk/commands/set_sensitive_env_vars.py +++ b/spacemk/commands/set_sensitive_env_vars.py @@ -1,10 +1,16 @@ import click from click.decorators import pass_meta_key +from click_help_colors import HelpColorsCommand from spacemk.spacelift import Spacelift -@click.command(help="Set sensitive environment variable values in Spacelift.") +@click.command( + cls=HelpColorsCommand, + help="Set sensitive environment variable values in Spacelift.", + help_headers_color="yellow", + help_options_color="green", +) @pass_meta_key("config") def set_sensitive_env_vars(config): spacelift = Spacelift(config.get("spacelift")) diff --git a/spacemk/commands/set_tf_vars_with_invalid_name.py b/spacemk/commands/set_tf_vars_with_invalid_name.py index fe45111..866ef06 100644 --- a/spacemk/commands/set_tf_vars_with_invalid_name.py +++ b/spacemk/commands/set_tf_vars_with_invalid_name.py @@ -1,10 +1,16 @@ import click from click.decorators import pass_meta_key +from click_help_colors import HelpColorsCommand from spacemk.spacelift import Spacelift -@click.command(help="Set value of Terraform variable with invalid name in Spacelift.") +@click.command( + cls=HelpColorsCommand, + help="Set value of Terraform variable with invalid name in Spacelift.", + help_headers_color="yellow", + help_options_color="green", +) @pass_meta_key("config") def set_tf_vars_with_invalid_name(config): spacelift = Spacelift(config.get("spacelift"))