Skip to content

Instantly share code, notes, and snippets.

@ganesshkumar
Last active January 14, 2017 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ganesshkumar/b7336e754f03cfb2506d8bff44069b2a to your computer and use it in GitHub Desktop.
Save ganesshkumar/b7336e754f03cfb2506d8bff44069b2a to your computer and use it in GitHub Desktop.
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)
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