Skip to content

Commit

Permalink
Add some color to help output (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 5, 2021
1 parent 75db4ed commit 4a867a3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Expand Up @@ -60,6 +60,7 @@ repos:
- id: pylint
additional_dependencies:
- GitPython
- click-help-colors
- importlib-metadata
- pytest
- rich
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
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
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
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
36 changes: 36 additions & 0 deletions src/mk/_typer.py
@@ -0,0 +1,36 @@
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=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
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
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -53,7 +53,7 @@ usedevelop = false
# don't install package itself in this env
skip_install = true
commands =
python -m pre_commit run --all-files --show-diff-on-failure
python -m pre_commit run {tty:--color=always} --all-files --show-diff-on-failure

[testenv:packaging]
description =
Expand Down

0 comments on commit 4a867a3

Please sign in to comment.