From 470b3370aa62c6282b82b8f00254e8b02078e4d7 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sun, 5 Mar 2023 16:55:19 +0000 Subject: [PATCH] Display detected commands in separated panel (#108) --- src/mk/__main__.py | 11 +++++++++-- src/mk/_typer.py | 20 ++------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/mk/__main__.py b/src/mk/__main__.py index 1dc3439..49d3aca 100644 --- a/src/mk/__main__.py +++ b/src/mk/__main__.py @@ -14,7 +14,7 @@ handlers: List[logging.Handler] console_err = Console(stderr=True) -app = CustomTyper(width=console_err.width) +app = CustomTyper(width=console_err.width, rich_markup_mode="rich") if "_MK_COMPLETE" in os.environ: level = logging.CRITICAL @@ -101,8 +101,15 @@ def cli() -> None: action.tool, action_name, ) + panel = "Detected commands" if action.tool else "" + short_help = action.description or "" + if action.tool: + short_help += f" [dim]({action.tool})[/dim]" app.command( - name=action_name, short_help=action.description, help=action.description + name=action_name, + short_help=short_help, + help=action.description, + rich_help_panel=panel, )(action.run) existing_commands.append(action_name) app() diff --git a/src/mk/_typer.py b/src/mk/_typer.py index 1f4416c..3e858a2 100644 --- a/src/mk/_typer.py +++ b/src/mk/_typer.py @@ -1,27 +1,11 @@ import typer -# from click_help_colors import HelpColorsCommand, HelpColorsGroup - - -# class CustomHelpColorsGroup(HelpColorsGroup): -# def __init__(self, *args, **kwargs) -> None: -# super().__init__(*args, **kwargs) -# self.help_headers_color = "blue" -# self.help_options_color = "yellow" - - -# class CustomHelpColorsCommand(HelpColorsCommand): -# def __init__(self, *args, **kwargs) -> None: -# super().__init__(*args, **kwargs) -# self.help_headers_color = "blue" -# self.help_options_color = "yellow" - class CustomTyper(typer.Typer): def __init__( self, *args, - cls=None, # CustomHelpColorsGroup, + cls=None, context_settings={ "help_option_names": ["-h", "--help"], }, @@ -40,7 +24,7 @@ def __init__( def command( self, *args, - cls=None, # cls=CustomHelpColorsCommand, + cls=None, context_settings={"help_option_names": ["-h", "--help"]}, **kwargs, ):