mando


Namemando JSON
Version 0.8.2 PyPI version JSON
download
home_pagehttps://mando.readthedocs.org/
SummaryCreate Python CLI apps with little to no effort at all!
upload_time2024-10-20 20:53:07
maintainerNone
docs_urlNone
authorMichele Lacchia
requires_pythonNone
licenseMIT
keywords argparse argument parser arguments cli command line commands decorator dispatch flags getopt options optparse parser subcommands
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            mando: CLI interfaces for Humans!
=================================

.. image:: https://img.shields.io/travis/rubik/mando
    :alt: Travis-CI badge
    :target: https://travis-ci.org/rubik/mando

.. image:: https://img.shields.io/coveralls/rubik/mando
    :alt: Coveralls badge
    :target: https://coveralls.io/r/rubik/mando

.. image:: https://img.shields.io/pypi/implementation/mando?label=%20&logo=python&logoColor=white
    :alt: PyPI - Implementation

.. image:: https://img.shields.io/pypi/v/mando
    :alt: Latest release
    :target: https://pypi.python.org/pypi/mando

.. image:: https://img.shields.io/pypi/l/mando
    :alt: PyPI - License
    :target: https://pypi.org/project/mando/

.. image:: https://img.shields.io/pypi/pyversions/mando
    :alt: PyPI - Python Version
    :target: https://pypi.org/project/mando/

.. image:: https://img.shields.io/pypi/format/mando
    :alt: Download format
    :target: http://pythonwheels.com/


mando is a wrapper around ``argparse``, and allows you to write complete CLI
applications in seconds while maintaining all the flexibility.

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

.. code-block:: console

    $ pip install mando

The problem
-----------

While ``argparse`` is great for simple command line applications with only
one, default command, when you have to add multiple commands and manage them
things get really messy and long. But don't worry, mando comes to help!

Quickstart
----------

.. code-block:: python

    from mando import command, main

    @command
    def echo(text, capitalize=False):
        '''Echo the given text.'''
        if capitalize:
            text = text.upper()
        print(text)

    if __name__ == '__main__':
        main()

Generated help:

.. code-block:: console

    $ python example.py -h
    usage: example.py [-h] {echo} ...

    positional arguments:
      {echo}
        echo      Echo the given text.

    optional arguments:
      -h, --help  show this help message and exit

    $ python example.py echo -h
    usage: example.py echo [-h] [--capitalize] text

    Echo the given text.

    positional arguments:
      text

    optional arguments:
      -h, --help    show this help message and exit
      --capitalize

Actual usage:

.. code-block:: console

    $ python example.py echo spam
    spam
    $ python example.py echo --capitalize spam
    SPAM


A *real* example
----------------

Something more complex and real-world-*ish*. The code:

.. code-block:: python

    from mando import command, main


    @command
    def push(repository, all=False, dry_run=False, force=False, thin=False):
        '''Update remote refs along with associated objects.

        :param repository: Repository to push to.
        :param --all: Push all refs.
        :param -n, --dry-run: Dry run.
        :param -f, --force: Force updates.
        :param --thin: Use thin pack.'''

        print ('Pushing to {0}. All: {1}, dry run: {2}, force: {3}, thin: {4}'
               .format(repository, all, dry_run, force, thin))


    if __name__ == '__main__':
        main()

mando understands Sphinx-style ``:param:``'s in the docstring, so it creates
short options and their help for you.

.. code-block:: console

    $ python git.py push -h
    usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository

    Update remote refs along with associated objects.

    positional arguments:
      repository     Repository to push to.

    optional arguments:
      -h, --help     show this help message and exit
      --all          Push all refs.
      -n, --dry-run  Dry run.
      -f, --force    Force updates.
      --thin         Use thin pack.

Let's try it!

.. code-block:: console

    $ python git.py push --all myrepo
    Pushing to myrepo. All: True, dry run: False, force: False, thin: False
    $ python git.py push --all -f myrepo
    Pushing to myrepo. All: True, dry run: False, force: True, thin: False
    $ python git.py push --all -fn myrepo
    Pushing to myrepo. All: True, dry run: True, force: True, thin: False
    $ python git.py push --thin -fn myrepo
    Pushing to myrepo. All: False, dry run: True, force: True, thin: True
    $ python git.py push --thin
    usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository
    git.py push: error: too few arguments

Amazed uh? Yes, mando got the short options and the help from the docstring!
You can put much more in the docstring, and if that isn't enough, there's an
``@arg`` decorator to customize the arguments that get passed to argparse.


Type annotations
----------------

mando understands Python 3-style type annotations and will warn the user if the
arguments given to a command are of the wrong type.

.. code-block:: python

    from mando import command, main


    @command
    def duplicate(string, times: int):
        '''Duplicate text.

        :param string: The text to duplicate.
        :param times: How many times to duplicate.'''

        print(string * times)


    if __name__ == '__main__':
        main()

.. code-block:: console

    $ python3 test.py duplicate "test " 5
    test test test test test
    $ python3 test.py duplicate "test " foo
    usage: test.py duplicate [-h] string times
    test.py duplicate: error: argument times: invalid int value: 'foo'


Mando has lots of other options. For example, it supports different docstring
styles (Sphinx, Google and NumPy), supports shell autocompletion via the
``argcomplete`` package and supports custom format classes. For a complete
documentation, visit https://mando.readthedocs.org/.

            

Raw data

            {
    "_id": null,
    "home_page": "https://mando.readthedocs.org/",
    "name": "mando",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "argparse, argument parser, arguments, cli, command line, commands, decorator, dispatch, flags, getopt, options, optparse, parser, subcommands",
    "author": "Michele Lacchia",
    "author_email": "michelelacchia@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/a0/40bfacdeb638e89b0193385caccc712a4f1aee2b6ff6b4284adf2822f9ce/mando-0.8.2.tar.gz",
    "platform": "any",
    "description": "mando: CLI interfaces for Humans!\n=================================\n\n.. image:: https://img.shields.io/travis/rubik/mando\n    :alt: Travis-CI badge\n    :target: https://travis-ci.org/rubik/mando\n\n.. image:: https://img.shields.io/coveralls/rubik/mando\n    :alt: Coveralls badge\n    :target: https://coveralls.io/r/rubik/mando\n\n.. image:: https://img.shields.io/pypi/implementation/mando?label=%20&logo=python&logoColor=white\n    :alt: PyPI - Implementation\n\n.. image:: https://img.shields.io/pypi/v/mando\n    :alt: Latest release\n    :target: https://pypi.python.org/pypi/mando\n\n.. image:: https://img.shields.io/pypi/l/mando\n    :alt: PyPI - License\n    :target: https://pypi.org/project/mando/\n\n.. image:: https://img.shields.io/pypi/pyversions/mando\n    :alt: PyPI - Python Version\n    :target: https://pypi.org/project/mando/\n\n.. image:: https://img.shields.io/pypi/format/mando\n    :alt: Download format\n    :target: http://pythonwheels.com/\n\n\nmando is a wrapper around ``argparse``, and allows you to write complete CLI\napplications in seconds while maintaining all the flexibility.\n\nInstallation\n------------\n\n.. code-block:: console\n\n    $ pip install mando\n\nThe problem\n-----------\n\nWhile ``argparse`` is great for simple command line applications with only\none, default command, when you have to add multiple commands and manage them\nthings get really messy and long. But don't worry, mando comes to help!\n\nQuickstart\n----------\n\n.. code-block:: python\n\n    from mando import command, main\n\n    @command\n    def echo(text, capitalize=False):\n        '''Echo the given text.'''\n        if capitalize:\n            text = text.upper()\n        print(text)\n\n    if __name__ == '__main__':\n        main()\n\nGenerated help:\n\n.. code-block:: console\n\n    $ python example.py -h\n    usage: example.py [-h] {echo} ...\n\n    positional arguments:\n      {echo}\n        echo      Echo the given text.\n\n    optional arguments:\n      -h, --help  show this help message and exit\n\n    $ python example.py echo -h\n    usage: example.py echo [-h] [--capitalize] text\n\n    Echo the given text.\n\n    positional arguments:\n      text\n\n    optional arguments:\n      -h, --help    show this help message and exit\n      --capitalize\n\nActual usage:\n\n.. code-block:: console\n\n    $ python example.py echo spam\n    spam\n    $ python example.py echo --capitalize spam\n    SPAM\n\n\nA *real* example\n----------------\n\nSomething more complex and real-world-*ish*. The code:\n\n.. code-block:: python\n\n    from mando import command, main\n\n\n    @command\n    def push(repository, all=False, dry_run=False, force=False, thin=False):\n        '''Update remote refs along with associated objects.\n\n        :param repository: Repository to push to.\n        :param --all: Push all refs.\n        :param -n, --dry-run: Dry run.\n        :param -f, --force: Force updates.\n        :param --thin: Use thin pack.'''\n\n        print ('Pushing to {0}. All: {1}, dry run: {2}, force: {3}, thin: {4}'\n               .format(repository, all, dry_run, force, thin))\n\n\n    if __name__ == '__main__':\n        main()\n\nmando understands Sphinx-style ``:param:``'s in the docstring, so it creates\nshort options and their help for you.\n\n.. code-block:: console\n\n    $ python git.py push -h\n    usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository\n\n    Update remote refs along with associated objects.\n\n    positional arguments:\n      repository     Repository to push to.\n\n    optional arguments:\n      -h, --help     show this help message and exit\n      --all          Push all refs.\n      -n, --dry-run  Dry run.\n      -f, --force    Force updates.\n      --thin         Use thin pack.\n\nLet's try it!\n\n.. code-block:: console\n\n    $ python git.py push --all myrepo\n    Pushing to myrepo. All: True, dry run: False, force: False, thin: False\n    $ python git.py push --all -f myrepo\n    Pushing to myrepo. All: True, dry run: False, force: True, thin: False\n    $ python git.py push --all -fn myrepo\n    Pushing to myrepo. All: True, dry run: True, force: True, thin: False\n    $ python git.py push --thin -fn myrepo\n    Pushing to myrepo. All: False, dry run: True, force: True, thin: True\n    $ python git.py push --thin\n    usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository\n    git.py push: error: too few arguments\n\nAmazed uh? Yes, mando got the short options and the help from the docstring!\nYou can put much more in the docstring, and if that isn't enough, there's an\n``@arg`` decorator to customize the arguments that get passed to argparse.\n\n\nType annotations\n----------------\n\nmando understands Python 3-style type annotations and will warn the user if the\narguments given to a command are of the wrong type.\n\n.. code-block:: python\n\n    from mando import command, main\n\n\n    @command\n    def duplicate(string, times: int):\n        '''Duplicate text.\n\n        :param string: The text to duplicate.\n        :param times: How many times to duplicate.'''\n\n        print(string * times)\n\n\n    if __name__ == '__main__':\n        main()\n\n.. code-block:: console\n\n    $ python3 test.py duplicate \"test \" 5\n    test test test test test\n    $ python3 test.py duplicate \"test \" foo\n    usage: test.py duplicate [-h] string times\n    test.py duplicate: error: argument times: invalid int value: 'foo'\n\n\nMando has lots of other options. For example, it supports different docstring\nstyles (Sphinx, Google and NumPy), supports shell autocompletion via the\n``argcomplete`` package and supports custom format classes. For a complete\ndocumentation, visit https://mando.readthedocs.org/.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Create Python CLI apps with little to no effort at all!",
    "version": "0.8.2",
    "project_urls": {
        "Download": "https://pypi.python.org/mando/",
        "Homepage": "https://mando.readthedocs.org/"
    },
    "split_keywords": [
        "argparse",
        " argument parser",
        " arguments",
        " cli",
        " command line",
        " commands",
        " decorator",
        " dispatch",
        " flags",
        " getopt",
        " options",
        " optparse",
        " parser",
        " subcommands"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cb81ab29c34824be434c78026dcf59aba743ea0653130b945790af9488f4b2e",
                "md5": "a27cd69458b8239c6ee62ff9c9477dc5",
                "sha256": "bad558078031366ee3bed2f290449be6788d8beaddcd20751105d30550534319"
            },
            "downloads": -1,
            "filename": "mando-0.8.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a27cd69458b8239c6ee62ff9c9477dc5",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 27789,
            "upload_time": "2024-10-20T20:53:05",
            "upload_time_iso_8601": "2024-10-20T20:53:05.535381Z",
            "url": "https://files.pythonhosted.org/packages/4c/b8/1ab29c34824be434c78026dcf59aba743ea0653130b945790af9488f4b2e/mando-0.8.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4a040bfacdeb638e89b0193385caccc712a4f1aee2b6ff6b4284adf2822f9ce",
                "md5": "f39593e6f5adad58c4d6583b06cdd9e2",
                "sha256": "539659d9a2fdc6c9a188211c58f381e0dafe9597085174c5472eb1ed0224b6b5"
            },
            "downloads": -1,
            "filename": "mando-0.8.2.tar.gz",
            "has_sig": false,
            "md5_digest": "f39593e6f5adad58c4d6583b06cdd9e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 37732,
            "upload_time": "2024-10-20T20:53:07",
            "upload_time_iso_8601": "2024-10-20T20:53:07.772745Z",
            "url": "https://files.pythonhosted.org/packages/c4/a0/40bfacdeb638e89b0193385caccc712a4f1aee2b6ff6b4284adf2822f9ce/mando-0.8.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-20 20:53:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "mando"
}
        
Elapsed time: 0.47030s