Skip to main content

Turn a dict of arguments into cli commands, ideal companion of docopt.

Project description

commandopt

Turn a dict of arguments into cli commands, ideal companion of docopt.

Why ?

Using the commandopt.commandopt decorator, you are able to declare commands to be executed depending on the input arguments of your app.

It reduces the boilerplate code in your main().

Example usage :

#myapp/myapp.py
"""Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py --version

Options:
  --version     Show version.

"""
from commandopt import Command
from docopt import docopt

import myapp.commands.ship

if __name__ == '__main__':
    arguments = docopt(__doc__, version='Naval Fate 2.0')
    run = Command(arguments)  # get the registered function
    run(arguments)  # execute the function
    # or
    # run = Command(arguments, call=True)
#myapp/commands/ship.py
from commandopt import commandopt

class ShipCommand:

    @commandopt(["ship", "new", "<name>"])
    @commandopt(["ship", "new"])
    def new(arguments):
        """You can stack the decorator if you want."""
        name = arguments["<name>"] or "case when name is empty"
        # ... your code here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Commandopt-0.1.0.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file Commandopt-0.1.0.tar.gz.

File metadata

  • Download URL: Commandopt-0.1.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

File hashes

Hashes for Commandopt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59a4dc2d68314411f3c6a3a1764c5ea4bcb7c82d556745aceaf4569213ea4ddd
MD5 6a54dd81c3c83317ff1abc89ab776d43
BLAKE2b-256 660d0fecd44509b265cda47d4421b45a39fe2ba597f2c155d571fc36847fe12e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page