Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created February 6, 2022 15:01
Show Gist options
  • Save MartinThoma/e49d65aa3f953b7fe3edb2d0d08a4401 to your computer and use it in GitHub Desktop.
Save MartinThoma/e49d65aa3f953b7fe3edb2d0d08a4401 to your computer and use it in GitHub Desktop.
import typer
from pathlib import Path
app = typer.Typer(help="Awesome app doing awesome things.", add_completion=False)
@app.command()
def spread(name: str, count: int = typer.Option(1, help="How much love you want")):
"""Spread the love."""
for i in range(count):
print(f"{name} loves you ❤️")
@app.command(name="print")
def print_(filepath: Path = typer.Option(..., exists=True), show_meta: bool = False):
"""Print the file."""
if show_meta:
print(f"File path: {filepath}")
print("-" * 80)
with open(filepath, "r") as f:
print(f.read())
if __name__ == "__main__":
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment