Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active February 6, 2022 14:57
Show Gist options
  • Save MartinThoma/81a59e391300c064accd8dc798d9a7db to your computer and use it in GitHub Desktop.
Save MartinThoma/81a59e391300c064accd8dc798d9a7db to your computer and use it in GitHub Desktop.
import click
@click.group()
def app():
"""Awesome app doing awesome things."""
@app.command()
@click.option("--count", default=1, help="How much love you want")
@click.argument("name")
def spread(name, count):
"""Spread the love."""
for i in range(count):
print(f"{name} loves you ❤️")
@app.command(name="print")
@click.argument("filepath", metavar="FILE", type=click.Path(exists=True))
@click.option("--show-meta", default=False, is_flag=True)
def print_(filepath, show_meta):
"""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