Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #51 from containenv/development
Browse files Browse the repository at this point in the history
0.1.2 Release
  • Loading branch information
dangle committed Jan 23, 2017
2 parents 040a83e + 19bdde6 commit c149a2b
Show file tree
Hide file tree
Showing 20 changed files with 803 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ deploy:
provider: pypi
user: dangle
password:
secure: lllkv5qDm+VJzuKwjglVw78OuLebBtB6ocCurc66sFl1CScwW1d0agBYUO/tFSjxYkgKhO+3/zkj+agyenz9ikbpIszmv0VuJAIuVhYVwcXJVb8Qgo8mQcfSkczj/EJJQk7StfeOshW5vUmpUSGFWlmZBAnbnipmoVrVxqTGlWi4UYIDvzswtv016iPOGpaOlZ/qXjwnGZKMoaVLsnwfaAHyGM4HTydUVU6QQzPTOqRZym3WYyj746FwsyMzLpYcLZK8lANuOU2eE8YxfU2cfbHDgikIg9Vp0x2PZDtuuP0YoPgdD4BJoV+FVth+aREjozKoBb0lO0cdGAuOs34q0oulLufX65TxPLPwGwuyyli1CWHySfO51sosGn1YfJiFpBODtWKBmSTAYmgmSq7rADy9dSVVpVoaTd3hRjn0c+sQYUTClNUqCcVTZVtts7CrfcOCFrmA6Qxza1Em14YdQ5TMQNbsl/a3ibl5tZIK1g5uRoYhsMmMlaMi4aGElvefOXI76uGquF/EkwPKx+59KpjVC09pC8VAJllFTVqmtZEB+GNE5TZ99rQof9kZKCzK83j3T9n3cR4L33mBi3ZYFoauuYexPFkwV5ZKpebjOnoUeipR4vQT0FF4N2hCkUDF9M6i0JNl7ZihWR2wwIeQYIx5Ymw8F+amloQybDQ5Clw=
secure: PgVFsaNvHX2c8rm0JHvypFYC4cnIvozr8OdGSl/AUdOAswffYBGgUatxJ4O7JbKvC1Ig0nIj5C6XAgxPuw9qsJ+Xkfdo1htVF6AEVPD/1n4rHstO3bToZV0STOJYZbKpPuugr2Y6lXlMDUKNjfsPq0A6KLaksXSvkW3/LZ81zncW5b+jMrfndZRuA64xN59qEAk2vFsvTYaVQOXJ9JgSTJ3OdTmcbTm1x+jzhDXqEL64RHDNLt+Ca5JSNagfSYyNx85J/3l36t76E4GH2pD3NEIfaIO2EQmqk1CPknhdUaGZUpVBP+6vitmrWShzVBSNgBbdTwonyYpqdrqp/YcIDSzD+QuLbrOLOmXRCDVTmmBwXp5+0wcDxolCXKFltrn5PdINBas70gAkiv3IKGMjggbD5vgZhp3hPMHSwalPtcAIFLIFFI2mXXVSyxJqtBz2pmSNhwdaFyeUU9hSC4/02Y9nqVePoxfVMAeybPnMckLFLW4EDgp1tNoepugMt8RSEQTMRcrTvkjZ9FtPNCHzAC909pLHqBHvK4CVx9+uxQQIR8peeg/bSODcvMYZ2frFkLiv/xBa5xL3Z57juKdEzRxycbrUzVBQML/KOUwL3WPSb8xk3NRD+69WLyzudFWuiShgtBcSZ2GWC/c1bUQKqH0bY8rUhOoqkh7XpHVFiK0=
on:
tags: true
repo: dangle/rapcom
repo: containenv/rcli
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

123 changes: 123 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
rcli
====

|PyPI| |Python Versions| |Build Status| |Coverage Status| |Code Quality|

*Rapidly create full-featured command line interfaces with help, subcommand
dispatch, and validation.*

**rcli** uses docopt_ to give you the control over your usage messages that you
want, but adds functionality such as automatic subcommand dispatching, usage
string wrapping, internationalization, and parameter validation.


Installation
------------

Install it using pip:

::

pip install rcli


Features
--------

- Automatic creation of console scripts and entry points based on usage
strings.
- Argument parsing based on usage string.
- Command line arguments are normalized into python function parameters.
- Validation of command line arguments using `PEP 484`_ type hints.
- Automatic generation of bash and zsh autocompletion scripts.
- Logging with multiple levels and crash log generation.
- Color coded logging based on log level.
- Extensible subcommand generation based on entry point groups.


Basic Usage
-----------

To use **rcli**, add ``rcli`` to your ``setup_requires`` argument in your
*setup.py* and set the ``autodetect_commands`` parameter to ``True``.

.. code-block:: python
from setuptools import setup
setup(
...,
setup_requires=['rcli'],
autodetect_commands=True,
...,
)
In your code, create a function with a usage string as its docstring and type
hint annotations for validation.

.. code-block:: python
def repeat(message: str, num: int):
"""Usage: repeat <message> [--num-times <num>]
Arguments:
message A message to print to the console.
Options:
-n, --num-times <num> The number of times to print the message [default: 1].
"""
for i in range(num):
print(message)
Once your package is installed, a new console script *repeat* will be
automatically generated that will validate and normalize your parameters and
call your function.


Subcommand Dispatch
-------------------

To generate a git-style command line interface with subcommand dispatching, you
only need to create your subcommand functions and your primary command will
be automatically generated for you.

.. code-block:: python
def roar():
"""Usage: cat-sounds roar"""
print('ROAR!')
def meow():
"""Usage: cat-sounds meow"""
print('Meow!')
This automatically generates the command *cat-sounds* with the following help
message::

Usage:
cat-sounds [--help] [--version] [--log-level <level> | --debug | --verbose]
<command> [<args>...]

Options:
-h, --help Display this help message and exit.
-V, --version Display the version and exit.
-d, --debug Set the log level to DEBUG.
-v, --verbose Set the log level to INFO.
--log-level <level> Set the log level to one of DEBUG, INFO, WARN, or ERROR.

'cat-sounds help -a' lists all available subcommands.
See 'cat-sounds help <command>' for more information on a specific command.


.. _PEP 484: https://www.python.org/dev/peps/pep-0484/
.. _docopt: http://docopt.org/

.. |Build Status| image:: https://travis-ci.org/containenv/rcli.svg?branch=development
:target: https://travis-ci.org/containenv/rcli
.. |Coverage Status| image:: https://coveralls.io/repos/github/containenv/rcli/badge.svg?branch=development
:target: https://coveralls.io/github/containenv/rcli?branch=development
.. |PyPI| image:: https://img.shields.io/pypi/v/rcli.svg
:target: https://pypi.python.org/pypi/rcli/
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/rcli.svg
:target: https://pypi.python.org/pypi/rcli/
.. |Code Quality| image:: https://api.codacy.com/project/badge/Grade/bfa6fff942654a27b4dc153e2876a111
:target: https://www.codacy.com/app/containenv/rcli?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=dangle/rcli&amp;utm_campaign=Badge_Grade
6 changes: 3 additions & 3 deletions examples/explicit_example/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
name='explicit_example',
version='1.0.0',
packages=['explicit_example'],
install_requires=['rapcom'],
install_requires=['rcli'],
entry_points={
'console_scripts': [
'say = rapcom.__main__:main'
'say = rcli.dispatcher:main'
],
'rapcom': [
'rcli': [
'say:hello = explicit_example:hello',
'say:hiya = explicit_example:hiya'
]
Expand Down
3 changes: 1 addition & 2 deletions examples/simple_example/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
name='simple_example',
version='1.0.0',
packages=['simple_example'],
install_requires=['rapcom'],
setup_requires=['rapcom'],
setup_requires=['rcli'],
autodetect_commands=True
)
10 changes: 0 additions & 10 deletions examples/validation_example/setup.py

This file was deleted.

18 changes: 0 additions & 18 deletions examples/validation_example/validation_example/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion rapcom/__init__.py → rcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

from __future__ import unicode_literals

__version_info__ = (0, 1, 1)
__version_info__ = (0, 1, 2, 'dev')
__version__ = '.'.join(map(str, __version_info__))
4 changes: 2 additions & 2 deletions rapcom/autodetect.py → rcli/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def setup_keyword(dist, _, value):
dist.entry_points = {}
for command, subcommands in six.iteritems(_get_commands(dist)):
dist.entry_points.setdefault('console_scripts', []).append(
'{command} = rapcom.__main__:main'.format(command=command)
'{command} = rcli.dispatcher:main'.format(command=command)
)
dist.entry_points.setdefault('rapcom', []).extend(subcommands)
dist.entry_points.setdefault('rcli', []).extend(subcommands)


def _get_commands(dist):
Expand Down
Loading

0 comments on commit c149a2b

Please sign in to comment.