Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Last active August 29, 2015 14:08
Show Gist options
  • Save joneskoo/3837fa1007ef8632670e to your computer and use it in GitHub Desktop.
Save joneskoo/3837fa1007ef8632670e to your computer and use it in GitHub Desktop.
Click example
#!/usr/bin/env python
import click
@click.group()
@click.option('--foo', help='This is great.')
def cli(foo):
pass
@cli.add_command
@click.command()
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(name):
"""Simple program that greets NAME."""
click.echo('Hello %s!' % name)
@cli.add_command
@click.command()
@click.option('--param', default='', help='Asdf.')
def world(param):
'''World domination'''
pass
if __name__ == '__main__':
cli()
(ve)grant:clitest joneskoo $ python cli.py
Usage: cli.py [OPTIONS] COMMAND [ARGS]...
Options:
--foo TEXT This is great.
--help Show this message and exit.
Commands:
hello Simple program that greets NAME.
world World domination
----------------------------------------------------------------------------------
(ve)grant:clitest joneskoo $ python cli.py hello --help
Usage: cli.py hello [OPTIONS]
Simple program that greets NAME.
Options:
--name TEXT The person to greet.
--help Show this message and exit.
----------------------------------------------------------------------------------
(ve)grant:clitest joneskoo $ python cli.py hello --name foo
Hello foo!
----------------------------------------------------------------------------------
(ve)grant:clitest joneskoo $ python cli.py hello
Your name: bar
Hello bar!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment