Skip to content

Instantly share code, notes, and snippets.

@hartleybrody
Last active February 8, 2023 14:38
Show Gist options
  • Save hartleybrody/63cda1c9b57a37be6ce541aaf5bb9d8f to your computer and use it in GitHub Desktop.
Save hartleybrody/63cda1c9b57a37be6ce541aaf5bb9d8f to your computer and use it in GitHub Desktop.
setting up multiple click commands within a single file
"""
Example of setting up multiple click commands within one file.
Run these commands with:
python /path/to/file.py do-foo --foo 'hello world'
Note that click converts '_' to '-' in function name
"""
import click
@click.group()
def cli():
# create group for all the commands so you can
# run them from the __name__ == "__main__" block
pass
@cli.command()
@click.option('-f', '--foo', required=True)
def do_foo(foo):
print(foo)
@cli.command()
@click.option('-b', '--bar', required=True)
def do_bar(bar):
print(bar)
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment