-
-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support click-help-colors [FEATURE] #47
Comments
You have to also provide the Command class, like: import typer
from click_help_colors import HelpColorsGroup, HelpColorsCommand
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"
app = typer.Typer(cls=CustomHelpColorsGroup)
@app.command(cls=CustomHelpColorsCommand)
def test_function(
name: str = typer.Option("World", "--name", "-n", help="name to say hello")
) -> None:
typer.echo(f"Hello {name}!")
@app.command(cls=CustomHelpColorsCommand)
def other() -> None:
typer.echo("other")
if __name__ == "__main__":
app() This is because But Typer doesn't modify nor use Click classes directly, when you use Typer doesn't modify the function to replace it with an instance of a class, instead, it registers the function to use and the class to use, and then it creates the specific objects when you call it. But doing it as described above should work fine (I just tested it 😄 ). |
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
Just wanted to add, if you want to avoid having to add the class LootMarshalTyper(typer.Typer):
def __init__(self, *args, cls=CustomHelpColorsGroup, **kwargs) -> None:
super().__init__(*args, cls=cls, **kwargs)
def command(self, *args, cls=CustomHelpColorsCommand, **kwargs) -> typer.Typer.command:
return super().command(*args, cls=cls, **kwargs) Hope this helps. |
Here is a full example I found of using click-help-color with typer https://github.com/daddycocoaman/AzDummy/blob/78438183c95102c5aed5af3578af31601bd7f423/azdummy/core/typer.py#L2 |
Apparently typer is no longer compatible with click-help-colors since 0.7 |
click-help-colors is no longer compatible with typer and the colours look fine as-is, so drop it. tiangolo/typer#47 (comment) fixes #33
click-help-colors is no longer compatible with typer and the colours look fine as-is, so drop it. tiangolo/typer#47 (comment) fixes #33
click-help-colors is no longer compatible with typer and the colours look fine as-is, so drop it. tiangolo/typer#47 (comment) fixes #33
Problem
I want to be able to replicate the functionality of click-contrib/click-help-colors to add colors to help text for easier readability
Ideal API
Attempted
By subclassing
HelpColorsGroup
and explicitly setting the colors in the__init__
it is possible to get colorsHowever the color does not propagate to sub command help text
The text was updated successfully, but these errors were encountered: