Created
March 4, 2016 19:31
-
-
Save gravesm/ffd73484d8e4d98b2e6b to your computer and use it in GitHub Desktop.
r2
This file contains 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
# -*- coding: utf-8 -*- | |
from itertools import repeat | |
import time | |
import unittest | |
import click | |
from click.testing import CliRunner | |
@click.group() | |
@click.version_option() | |
@click.option('--debug/--no-debug', default=False) | |
def main(debug): | |
if debug: | |
click.echo('R2 is now debugging.') | |
@main.command() | |
@click.option('--dev', prompt=True, envvar="DEV") | |
def candy(dev): | |
"""Congratulate a developer on a job well done.""" | |
click.echo("♬ This commit was a triumph ♪ ♫") | |
click.echo("Keep up the good work, %s." % dev) | |
@main.command() | |
@click.argument('dev') | |
@click.confirmation_option(prompt="Are you sure you want to shock someone?") | |
@click.option('-v', count=True, default=1, | |
help="Supply multiple times to increase voltage.") | |
def shock(v, dev): | |
"""Gently correct a developer.""" | |
click.secho("%s" % "".join(repeat(u"⚡", v)), bg='yellow', fg='black') | |
click.echo("Improve your work or you will be reported, %s." % dev) | |
@main.command() | |
@click.argument('msg', type=click.File('rb')) | |
@click.argument('devs', nargs=-1) | |
def report(msg, devs): | |
"""Report the devs who have failed to comply.""" | |
with click.progressbar(range(10), | |
label='Generating report. Hold on.') as bar: | |
for i in bar: | |
time.sleep(0.3) | |
click.echo(msg.read()) | |
click.echo(" ".join(devs)) | |
class TestStuff(unittest.TestCase): | |
def setUp(self): | |
self.runner = CliRunner() | |
def test_shock_corrects_developer(self): | |
res = self.runner.invoke(main, ['shock', '--yes', 'Foo']) | |
assert res.exit_code == 0 | |
def test_shock_uses_correct_voltage(self): | |
res = self.runner.invoke(main, ['shock', '--yes', '-vvvvv', 'Foo']) | |
assert u"⚡⚡⚡⚡⚡" in res.output |
This file contains 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
# -*- coding: utf-8 -*- | |
from setuptools import setup | |
setup( | |
name='r2', | |
version='1.0.0', | |
py_modules=['cli'], | |
install_requires=[ | |
'click', | |
], | |
entry_points={ | |
'console_scripts': [ | |
'r2=cli:main' | |
] | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment