A python framwork to write large CLIs using dependency injection
Project description
======
bigcli
======
.. image:: https://img.shields.io/pypi/v/bigcli.svg
:target: https://pypi.python.org/pypi/bigcli
.. image:: https://img.shields.io/travis/dudadornelles/bigcli.svg
:target: https://travis-ci.org/dudadornelles/bigcli
.. image:: https://readthedocs.org/projects/bigcli/badge/?version=latest
:target: https://bigcli.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://pyup.io/repos/github/dudadornelles/bigcli/shield.svg
:target: https://pyup.io/repos/github/dudadornelles/bigcli/
:alt: Updates
A python framework to write large CLIs. The concept is to automagically derive CLI commands and args based on the object graph of a callable class that implements a CLI command (command name is derived from the class name). It uses argparse_ to create the CLI parser and pinject_ as the Dependency_Injection_ engine. You implement a class - e.g.: ``DoSomething``- and that generates the name of a subcommand - e.g: ``do-something``. Then, based on the dependencies of class ``DoSomething``, we will derive the arguments, e.g.: if ``DoSomething`` depends on ``Dependency``, which in turn declares ``__args__ = [bigcli.arg('--option', required=False, help='help')]`` (add_argument_ method from argparse_), then command ``do-something`` will have a '--option' argument.
In theory, the auto-generation of arguments should enables and encourage the reuse of internal components for rapid development of consistent and testable rich CLIs, especially those that operate platforms.
* Free software: MIT license
* Documentation: https://bigcli.readthedocs.io.
Minimal example:
-------
.. code-block:: python
#!/usr/bin/env python
import bigcli
class Dependency(object):
__args__ = [
bigcli.arg('--option') # short for ``lambda p: p.add_argument('--option')``
]
def __init__(self, args):
self.option = args.option
class Command(object):
__parent__ = 'sub-command'
__depends_on__ = [Dependency]
def __init__(self, dependency):
self.dependency = dependency
def __call__(self):
print "dependency option: {}".format(self.dependency.option)
if __name__ == "__main__":
bigcli.BigCli(commands=[Command]).execute()
# $ ./example.py sub-command command --option value
# > dependency option: value
Features (see tests for example)
--------
* Auto generates parsers and commands using the ``__depends_on__`` and ``__args__`` attributes.
* Supports adding single subcommand using the ``__parent__ = 'subcommand'`` attribute.
Known Issues:
-------------
* Only supports python 2.7 because pinject_ only supports python 2.7.
* Class names should have more than a single letter (pinject know issue, not documented anywhere AFAIK).
Credits
---------
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
.. _Dependency_Injection: https://en.wikipedia.org/wiki/Dependency_injection
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
.. _add_argument: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
.. _argparse: https://docs.python.org/2/howto/argparse.html
.. _pinject: https://github.com/google/pinject
=======
History
=======
0.1.0 (2017-07-25)
------------------
* First release on PyPI.
bigcli
======
.. image:: https://img.shields.io/pypi/v/bigcli.svg
:target: https://pypi.python.org/pypi/bigcli
.. image:: https://img.shields.io/travis/dudadornelles/bigcli.svg
:target: https://travis-ci.org/dudadornelles/bigcli
.. image:: https://readthedocs.org/projects/bigcli/badge/?version=latest
:target: https://bigcli.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://pyup.io/repos/github/dudadornelles/bigcli/shield.svg
:target: https://pyup.io/repos/github/dudadornelles/bigcli/
:alt: Updates
A python framework to write large CLIs. The concept is to automagically derive CLI commands and args based on the object graph of a callable class that implements a CLI command (command name is derived from the class name). It uses argparse_ to create the CLI parser and pinject_ as the Dependency_Injection_ engine. You implement a class - e.g.: ``DoSomething``- and that generates the name of a subcommand - e.g: ``do-something``. Then, based on the dependencies of class ``DoSomething``, we will derive the arguments, e.g.: if ``DoSomething`` depends on ``Dependency``, which in turn declares ``__args__ = [bigcli.arg('--option', required=False, help='help')]`` (add_argument_ method from argparse_), then command ``do-something`` will have a '--option' argument.
In theory, the auto-generation of arguments should enables and encourage the reuse of internal components for rapid development of consistent and testable rich CLIs, especially those that operate platforms.
* Free software: MIT license
* Documentation: https://bigcli.readthedocs.io.
Minimal example:
-------
.. code-block:: python
#!/usr/bin/env python
import bigcli
class Dependency(object):
__args__ = [
bigcli.arg('--option') # short for ``lambda p: p.add_argument('--option')``
]
def __init__(self, args):
self.option = args.option
class Command(object):
__parent__ = 'sub-command'
__depends_on__ = [Dependency]
def __init__(self, dependency):
self.dependency = dependency
def __call__(self):
print "dependency option: {}".format(self.dependency.option)
if __name__ == "__main__":
bigcli.BigCli(commands=[Command]).execute()
# $ ./example.py sub-command command --option value
# > dependency option: value
Features (see tests for example)
--------
* Auto generates parsers and commands using the ``__depends_on__`` and ``__args__`` attributes.
* Supports adding single subcommand using the ``__parent__ = 'subcommand'`` attribute.
Known Issues:
-------------
* Only supports python 2.7 because pinject_ only supports python 2.7.
* Class names should have more than a single letter (pinject know issue, not documented anywhere AFAIK).
Credits
---------
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
.. _Dependency_Injection: https://en.wikipedia.org/wiki/Dependency_injection
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
.. _add_argument: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
.. _argparse: https://docs.python.org/2/howto/argparse.html
.. _pinject: https://github.com/google/pinject
=======
History
=======
0.1.0 (2017-07-25)
------------------
* First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bigcli-0.2.0.tar.gz
(14.4 kB
view details)
Built Distribution
File details
Details for the file bigcli-0.2.0.tar.gz
.
File metadata
- Download URL: bigcli-0.2.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cde8b789ef760b03879d85dd0ff1f646463c598187fbda09bb1f64c0502cdbd1 |
|
MD5 | bd9f2cff7b55167c8b97fda79e4dbd4e |
|
BLAKE2b-256 | afd17d3c2f9d30b2cb0dbd498bd2cd699aee6940f9953e64ad27b443131b290b |
File details
Details for the file bigcli-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: bigcli-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ebe3a4fe67d57c9eff28a8c5aca8a51e44d752d275bc1e1532fe750f6d07b4 |
|
MD5 | 5cf12348f9bfc5b5b447f40927ae7624 |
|
BLAKE2b-256 | 93a0f56c156bea478b01aa2e0d0aa0e6bacf7bfd43b74574c036c43b89d18e4e |