Created
March 13, 2021 18:53
-
-
Save jhrcook/30a6f51d7541fed9b6c4c254a0abef3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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