Last active
August 29, 2015 14:08
-
-
Save joneskoo/3837fa1007ef8632670e to your computer and use it in GitHub Desktop.
Click example
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 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() | |
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
(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