This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

If your parser has less than five subcommands, you can parse them with argparse. If you have more, you still can, but you will get a huge, unreadable code. This module makes this easier by dispatching subcommand calls to functions, modules or binaries.

Examples

Example 1 : Manual definition of subcommands

For instance, consider the following code for mycommand.py:

import sys
from argdispatch import ArgumentParser

def foo(args):
    """A function associated to subcommand `foo`."""
    print("Doing interesting stuff")
    sys.exit(1)

if __name__ == "__main__":
    parser = ArgumentParser()
    subparser = parser.add_subparsers()

    subparser.add_function(foo)
    subparser.add_package("bar")
    subparser.add_binary("baz")

    subparser.parse_args()

With this simple code:

  • mycommand.py foo -v --arg=2 is equivalent to the python code foo(['-v', '--arg=2']);
  • mycommand.py bar -v --arg=2 is equivalent to python -m bar -v --arg=2;
  • mycommand.py baz -v --arg=2 is equivalent to baz -v --arg=2.

Then, each function, module or binary does whatever it wants with the arguments.

Example 2 : Automatic definition of subcommands

With programs like git, if a git-foo binary exists, then calling git foo --some=arguments is equivalent to git-foo --some=arguments. The following code, in myprogram.py copies this behaviour:

import sys
from argdispatch import ArgumentParser

if __name__ == "__main__":
    parser = ArgumentParser()
    subparser = parser.add_subparsers()

    subparser.add_iter_modules("myprogram")
    subparser.add_prefix_binaries("myprogram-")

    subparser.parse_args()

With this program, given that binary myprogram-foo and python module myprogram.bar.__main__.py exist:

  • myprogram foo -v --arg=2 is equivalent to myprogram-foo -v --arg=2;
  • myprogram bar -v --arg=2 is equivalent to python -m myprogram.bar -v --arg=2.

Documentation

The complete documentation is available on readthedocs.

To compile it from source, download and run:

cd doc && make html

What’s new?

See changelog.

Download and install

  • From sources:

  • From pip:

    pip install argdispatch
    
  • Quick and dirty Debian (and Ubuntu?) package

    This requires stdeb to be installed:

    python3 setup.py --command-packages=stdeb.command bdist_deb
    sudo dpkg -i deb_dist/argdispatch-<VERSION>_all.deb
    
Release History

Release History

0.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0b1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
argdispatch-0.1.1-py3-none-any.whl (10.2 kB) Copy SHA256 Checksum SHA256 py3 Wheel May 21, 2016
argdispatch-0.1.1.tar.gz (34.7 kB) Copy SHA256 Checksum SHA256 Source May 21, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting