I'm trying to use typer to build a CLI application. I'm also using rich to do some formatting. However having rich installed leads to typer using rich_help_panel. I would like to disable that. I would prefer the normal formatting of the help string. How can I achieve that?
What I have tried so far:
import typer
from typing_extensions import Annotated
cli = typer.Typer(rich_help_panel=None)
@cli.command()
def multiply(x: int, y: int, exp: bool = False):
"""
Multiply two numbers.
"""
if exp:
return print(x**y)
return print(x * y)
@cli.command()
def sum(x: int, y: int):
"""
Sum two numbers.
"""
return print(x + y)
@cli.callback()
def main():
"Does arithmetic"
if __name__ == "__main__":
cli()
The parameter rich_help_panel is for setting the rich panel title text as described here. The functionality you are looking for doesn't exist. At least not yet. I made a pull request to add a setter to globally disable the rich help text and the rich traceback respectively.
If someone reading this wants to get this merged I would suggest to write a review of my PR according to this.
Edit:
In the meantime you can either use
typer = {git = "https://github.com/JacobKochems/typer.git"}
in your pyproject.toml as a dependency or the following workaround:
In the meantime you can use the following workaround:
import typer.core
typer.core.rich = None
as suggested here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With