Last active
January 14, 2017 09:11
-
-
Save ganesshkumar/b7336e754f03cfb2506d8bff44069b2a to your computer and use it in GitHub Desktop.
Click Quickstart (http://click.pocoo.org/5/quickstart)
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
import click | |
class Config(object): | |
def __init__(self): | |
self.verbose = False | |
pass_config = click.make_pass_decorator(Config, ensure=True) | |
@click.group() | |
@click.option('--verbose', is_flag=True) | |
@pass_config | |
def cli(config, verbose): | |
config.verbose = verbose | |
@cli.command() | |
@click.option('--string', default='World', help='Object to be greeted') | |
@click.option('--repeat', default=1, help='Number of times to be greeted') | |
@click.argument('out', type=click.File('w'), default='-', required=False) | |
@pass_config | |
def say(config, string, repeat, out): | |
"""This script greets you""" | |
if (config.verbose): | |
click.echo('We are in verbose mode') | |
for count in xrange(repeat): | |
click.echo('Hello %s!' % string, file=out) |
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
from setuptools import setup | |
setup( | |
name='Hello World', | |
version='1.0', | |
py_modules=['click'], | |
install_requires=[ | |
'click', | |
], | |
entry_points=''' | |
[console_scripts] | |
click=hello:cli | |
''' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment