Skip to content

Commit

Permalink
Add command help text
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Graves committed Nov 24, 2015
1 parent 44926c7 commit 7ba5e79
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
13 changes: 10 additions & 3 deletions carbon/__init__.py
@@ -1,5 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
"""
carbon
******
from carbon.app import people, PersonFeed
from carbon.db import engine, session
A tool for generating people.
"""

__version__ = '0.0.1'

from .app import people, PersonFeed
from .db import engine, session
12 changes: 10 additions & 2 deletions carbon/cli.py
Expand Up @@ -8,14 +8,22 @@


@click.group()
@click.version_option()
def main():
pass


@main.command()
@click.option('--db', default='sqlite:///carbon.db')
@click.option('--url')
@click.argument('db')
@click.option('--url', help='URL for API endpoint')
def load(db, url):
"""Generate a feed of person data.
The data is pulled from a database identified by DB, which should
be a valid SQLAlchemy database connection string. The feed will
be POSTed to URL if given, otherwise, it will be written to
stdout.
"""
engine.configure(db)
feed = PersonFeed()
for person in people():
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Expand Up @@ -4,16 +4,20 @@
"""

import io
import re
from setuptools import find_packages, setup


with io.open('LICENSE') as f:
license = f.read()

with open('carbon/__init__.py', 'r') as fp:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', fp.read(),
re.MULTILINE).group(1)

setup(
name='carbon',
version='0.0.1',
version=version,
description='Load people into Elements',
long_description=__doc__,
url='https://github.com/MITLibraries/carbon',
Expand Down
7 changes: 3 additions & 4 deletions tests/test_cli.py
Expand Up @@ -18,8 +18,7 @@ def runner():


def test_load_returns_people(runner, E, xml_data):
res = runner.invoke(main, ['load', '--db',
'sqlite:///tests/db/test.db'])
res = runner.invoke(main, ['load', 'sqlite:///tests/db/test.db'])
assert res.exit_code == 0
assert res.output.encode('utf-8') == \
ET.tostring(xml_data, encoding="UTF-8", xml_declaration=True) + b'\n'
Expand All @@ -28,8 +27,8 @@ def test_load_returns_people(runner, E, xml_data):
def test_load_posts_to_url(runner, E, xml_data):
with requests_mock.Mocker() as m:
m.post('http://example.com', text='congrats')
runner.invoke(main, ['load', '--db', 'sqlite:///tests/db/test.db',
'--url', 'http://example.com'])
runner.invoke(main, ['load', 'sqlite:///tests/db/test.db', '--url',
'http://example.com'])
req = m.request_history[0]
assert req.text.encode('utf-8') == ET.tostring(xml_data,
encoding="UTF-8",
Expand Down

0 comments on commit 7ba5e79

Please sign in to comment.