Django-docopt-command allows you to write Django manage.py commands using the docopt library.
Project description
Django docopt command
Django-docopt-command allows you to write Django manage.py commands using the docopt library. This means that you can define commands using usage strings.
References:
- Django: The Web framework for perfectionists with deadlines
- The docopt library: Command-line interface description language
- Writing custom django-admin commands
class Command(DocOptCommand):
# This usage string defines the command options:
docs = "Usage: command <option1> <option2> [--flag1]"
def handle_docopt(self, arguments):
# arguments contains a dictionary with the options
pass
Django-docopt-command is tested with Django 2.2 - 3.1 and Python 3.5 - 3.8 and is hosted on github.
Note that version 1.0.0 also supports Django 2.1 and version 0.5.0 supports Django 1.11 and Django 2.0.
Example
See the testproject/docopt_example in the django-docopt-command github repository.
Usage
Install django-docopt-command.
pip install django-docopt-command
Step 1 - management command
Write a Django custom management command, as described in Writing custom django-admin commands.
Step 2 - inherit from DocOptCommand
class Command(DocOptCommand):
pass
Step 3 - add a docs string
class Command(DocOptCommand):
docs = "Usage: command <option1> <option2> [--flag1]"
Step 4 - override handle_docopt
class Command(DocOptCommand):
docs = "Usage: command <option1> <option2> [--flag1]"
def handle_docopt(self, arguments):
option1 = arguments['option1']
option2 = arguments['option2']
License
Django-docopt-command is licensed under the Apache 2.0 License.
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
Built Distributions
Hashes for django-docopt-command-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed52c2ab73c4facd353edc6a70b54d4054e9ec0484c9b58a30eae702da86a0f6 |
|
MD5 | a0fb22b78d8c3bb1308cba2ad093613a |
|
BLAKE2b-256 | e16dc51cb829d25ec2090cd3f286b5d6c9a95200fe277fa79be9d3c691acd2e9 |
Hashes for django_docopt_command-1.1.0-py3.8.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8db9b4814ba1cd1bd899ea484e8d3f42a92b67c4a6ff0dfa861bffbfd6cf35e6 |
|
MD5 | 786d8d0e9e9573975f6c36acd8e5e100 |
|
BLAKE2b-256 | 59fdd347ac5aa881ba86a499cfbd008e4a7113099df6ca5351705ce03522b77f |
Hashes for django_docopt_command-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee42da41adfb1ac263eeae5c118178a75538ef829ab1cb7a10b6f87a7c8579a |
|
MD5 | f46508fec9d8b96ae121f160a1a1cfe7 |
|
BLAKE2b-256 | 7b358446c743dd14e8ea404732eedc8100763a0fc1f72e7724768371749051cc |