Skip to content

Instantly share code, notes, and snippets.

@jhrcook
Created March 13, 2021 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhrcook/30a6f51d7541fed9b6c4c254a0abef3c to your computer and use it in GitHub Desktop.
Save jhrcook/30a6f51d7541fed9b6c4c254a0abef3c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# How to get Typer to behave like it has a default command.
# source: https://github.com/tiangolo/typer/issues/18#issuecomment-617089716
import typer
app = typer.Typer()
@app.command()
def foo(x: str):
print("message:" + x)
@app.command()
def bar(i: int):
print(i + 2)
@app.callback(invoke_without_command=True)
def pas(ctx: typer.Context):
if ctx.invoked_subcommand is None:
print("this is the callback")
if __name__ == "__main__":
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment