Skip to content

Commit

Permalink
Display detected commands in separated panel (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 5, 2023
1 parent f085933 commit 470b337
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
11 changes: 9 additions & 2 deletions src/mk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 2 additions & 18 deletions src/mk/_typer.py
Original file line number Diff line number Diff line change
@@ -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"],
},
Expand All @@ -40,7 +24,7 @@ def __init__(
def command(
self,
*args,
cls=None, # cls=CustomHelpColorsCommand,
cls=None,
context_settings={"help_option_names": ["-h", "--help"]},
**kwargs,
):
Expand Down

0 comments on commit 470b337

Please sign in to comment.