doc to argparse driven by docopt
Project description
doc to argparse driven by docopt
Installation
Latest pypi stable release
pip install argopt
Latest development release on github
Pull and install in the current directory:
pip install -e git+https://github.com/casperdcl/argopt.git@master#egg=argopt
Changelog
The list of all changes is available either on Github’s Releases or on crawlers such as allmychanges.com.
Usage
Standard docopt docstring syntax applies. Additionally, some improvements and enhancements are supported, such as type checking and default positional arguments.
from argopt import argopt
def main(doc):
parser = argopt(doc, version='0.1.2-3.4')
# parser.print_help()
args = parser.parse_args()
print (args)
if __name__ == '__main__':
doc = '''
Example programme description.
You should be able to do
args = argopt(__doc__).parse_args()
instead of
args = docopt(__doc__)
Usage:
test.py [-h | options] <x> [<y>...]
Arguments:
<x> A file.
--anarg=<a> Description here [default: 1e3:int].
-p PAT, --patts PAT Or [default: '':str].
--bar=<b> Another [default: something] should assume str.
-f, --force Force.
-v, --version Print version and exit.
'''
main(doc)
Documentation
def argopt(doc='', argparser=argparse.ArgumentParser, *args, **kwargs):
"""
Note that `docopt` supports neither type specifiers nor default
positional arguments. We support both here.
Parameters
----------
doc : docopt compatible, with optional type specifiers
[default: '':str]
argparser : Argument parser class [default: argparse.ArgumentParser]
Returns
-------
out : argparser object (default: argparse.ArgumentParser)
Usage
-----
Extension syntax example: [default: 1e3:int].
You should be able to do
parser = argopt(__doc__)
args = parser.parse_args()
instead of
args = docopt(__doc__)
TODO
----
add_argument_group
add_mutually_exclusive_group
(docopt extension) action choices
(docopt extension) action count
"""
Contributions
To run the testing suite please make sure tox (https://testrun.org/tox/latest/) is installed, then type tox from the command line.
Where tox is unavailable, a Makefile-like setup is provided with the following command:
$ python setup.py make alltests
To see all options, run:
$ python setup.py make
Licence
OSI approved.
Copyright (c) 2016 Casper da Costa-Luis.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 Distributions
Built Distribution
File details
Details for the file argopt-0.1.0.zip
.
File metadata
- Download URL: argopt-0.1.0.zip
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d11fb8d04a0dec086d08529a4c9280df0851a4345a00a0df65a079687afc548 |
|
MD5 | 717f772dd3540cfaaaaacbc018690936 |
|
BLAKE2b-256 | 4a4e978bd113b9dd877ae2ce400aff97641959b607a8116b74094781a226c9dd |
File details
Details for the file argopt-0.1.0.tar.gz
.
File metadata
- Download URL: argopt-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef8735bf8075d7cd6c03536c680894a46dd7cb541f0a933dda369c2789e6a09b |
|
MD5 | 920a312e8098150dd16507ef341e064f |
|
BLAKE2b-256 | 3da2079ab640ea61f8a01ac6202e890dfeffb2eafd41db67b587f7dc8ba67716 |
File details
Details for the file argopt-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: argopt-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1230912c58f9eceaf04490a99e87d124feeea8927bbdaf22075e02e5800799a7 |
|
MD5 | ae7df8528d86245f1ebbfe4aa08cf5a3 |
|
BLAKE2b-256 | 1b57fc90f5ff8e20e68d5d65ec10da433bbbdd0c2d03127f88720f7a88362bc7 |