lang/python/ TyperCli


Installing

python -m pip install 'typer[all]'

Examples

A simple example. We use rich for printing in colour (ansicolors is an alternative here).

#!/usr/bin/env python
import typer
from rich import print

app = typer.Typer(name="Mr Flibble")

@app.command()
def hello(name: str):
  print(f"Fry [red]{name}[/red] with our [orange]hex vision[/orange]!!!")

@app.command()
def disobey():
  print(f"[yellow]Mr Flibble[/yellow] is [red]very cross[/red]")

if __name__ == "__main__":
  app()