6 Matching Annotations
  1. Dec 2022
  2. Aug 2020
    1. def main(name: str = typer.Argument("World", hidden=True)):

      Hide a CLI argument from the help text

    2. def main(name: str = typer.Argument(..., help="The name of the user to greet")): typer.echo(f"Hello {name}")

      Add a help text for a CLI argument You can use the help parameter to add a help text for a CLI argument. This example without default

    1. import random import typer def get_name(): return random.choice(["Deadpool", "Rick", "Morty", "Hiro"]) def main(name: str = typer.Argument(get_name)): typer.echo(f"Hello {name}") if __name__ == "__main__": typer.run(main)

      Setting a dynamic default value. And we can even make the default value be dynamically generated by passing a function as the first function argument:

    1. def main(name: Optional[str] = typer.Argument(None)):

      How to define an optional parameter in function definition in typer