Skip to content

Commit

Permalink
Add some color to help output
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 5, 2021
1 parent 75db4ed commit f95b698
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#
blessings==1.7
# via mk (setup.cfg)
click-help-colors==0.9
# via mk (setup.cfg)
click==7.1.2
# via
# click-help-colors
# mk (setup.cfg)
# typer
colorama==0.4.4
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
GitPython
blessings
click >= 7.1.2
click-help-colors
colorama # for Windows
importlib-metadata
pygments
Expand All @@ -48,7 +49,6 @@ install_requires =
shellingham
typer


[options.packages.find]
where = src

Expand Down
7 changes: 5 additions & 2 deletions src/mk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from rich.logging import RichHandler

from mk import __version__
from mk._typer import CustomTyper
from mk.ctx import ctx

app = typer.Typer()
app = CustomTyper()
handlers: List[logging.Handler]
console_err = Console(stderr=True)

Expand All @@ -37,10 +38,11 @@ def version_callback(value: bool) -> None:

@app.callback()
def main(
# click_ctx: typer.Context,
# pylint: disable=unused-argument
version: bool = typer.Option(
None, "--version", callback=version_callback, is_eager=True
) # noqa: B008
), # noqa: B008
) -> None:
return

Expand Down Expand Up @@ -88,6 +90,7 @@ def cli() -> None:
action.run
)
existing_commands.append(action_name)
# breakpoint()
app()


Expand Down
38 changes: 38 additions & 0 deletions src/mk/_typer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from click_help_colors import HelpColorsGroup, HelpColorsCommand
import typer


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=CustomHelpColorsGroup,
context_settings={"help_option_names": ["-h", "--help"]},
**kwargs
) -> None:
super().__init__(*args, cls=cls, context_settings=context_settings, **kwargs)

def command(
self,
*args,
cls=CustomHelpColorsCommand,
context_settings={"help_option_names": ["-h", "--help"]},
**kwargs
):
return super().command(
*args, cls=cls, context_settings=context_settings, **kwargs
)
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ attrs==20.3.0
# via pytest
blessings==1.7
# via mk (setup.cfg)
click-help-colors==0.9
# via mk (setup.cfg)
click==7.1.2
# via
# click-help-colors
# mk (setup.cfg)
# typer
colorama==0.4.4
Expand Down

0 comments on commit f95b698

Please sign in to comment.