arguments
Argument parser based on docopt
install
pip install arguments
usage
Docopt is used for parsing the docstring (doc), arguments bundles the schema parser and returns a OptionParser like object with normalized attributes
For example
# coding=utf-8
"""
arguments test
Usage:
tests.py [options] <posarg1> <posarg2>
Options:
-h --help Show this screen.
-o --option=<option1> An option.
--opt2=<option2> An option [default: hello].
-p --parameter=<parameter> Folder to check the git repos out [default: 77].
-v --verbose Folder from where to run the command [default: .].
"""
from arguments import Arguments
def main():
"""
main
"""
arg = Arguments()
print(arg)
if __name__ == "__main__":
main()
gives
$ python main.py pval1 pval2
<arguments.Arguments object at 0x1022e0eb8>
options :
opt2 : hello
option : None
parameter : 77
help : False
verbose : False
positional :
posarg1 : pval1
posarg2 : pval2
usage with classes
(examples/classbased.py)
A nested docker style commandline program (python3)
class BaseArguments(arguments.Arguments):
def __init__(self, doc):
...
class MainArguments(BaseArguments):
def __init__(self):
doc = """
Some tools.
Usage:
classbased.py [options] [--] <tool> [<args>...]
Options:
-h --help Show this screen..
-v --verbose Verbose mode.
Commands:
tool1 Tool1 description here
tool2 Tool2 ...
"""
super().__init__(doc)
class Tool1Arguments(BaseArguments):
def __init__(self):
doc = """
Tool 1
Usage:
classbased.py tool1 [options] [--] <command> [<args>...]
Options:
-h --help Show this screen..
-v --verbose Verbose mode.
Commands:
run Run the tool
build Build the tool
"""
super().__init__(doc)
class Tool2Arguments(BaseArguments):
def __init__(self):
doc = """
Tool 2
Usage:
classbased.py tool2 [options] [--] <command> [<args>...]
Options:
-h --help Show this screen..
-v --verbose Verbose mode.
Commands:
upload Upload something
delete Delete something
"""
super().__init__(doc)
$ python classbased.py
Usage:
classbased.py [options] [--] <tool> [<args>...]
$ python classbased.py -h
Some tools.
Usage:
classbased.py [options] [--] <tool> [<args>...]
Options:
-h --help Show this screen..
-v --verbose Verbose mode.
Commands:
tool1 Tool1 description here
tool2 Tool2 ...
$ python classbased.py tool1 run
<__main__.Tool1Arguments object at 0x10d45cac8>
options:
help: False
verbose: False
positional:
args: []
command: run
Using schema
Assume you are using docopt with the following usage-pattern:
my_program.py [--count=N] <path> <files>
and you would like to validate that <files> are readable, and that <path> exists, and that --count is either integer from 0 to 5, or None.
this is how you validate it using schema:
>>> from arguments import *
>>> s = Schema({'<files>': [Use(open)],
... '<path>': os.path.exists,
... '--count': Or(None, And(Use(int), lambda n: 0 < n < 5))})
>>> args = Arguments(validateschema=s)
>>> args.files
[<open file 'LICENSE-MIT', mode 'r' at 0x...>, <open file 'setup.py', mode 'r' at 0x...>]
>>> args.path
'../'
>>> args.count
3
As you can see, it validated data successfully, opened files and converted '3' to int.
Metadata
Release files for arguments 32
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| arguments-32.tar.gz | 14.3 kB | Without provenance | Details for arguments-32.tar.gz |
Release files / arguments-32.tar.gz
| Download URL | arguments-32.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6c2ec3353a954b8b14be9c2eba405ff906f16e60061fd5be64ea1d439cff600
|
|
BLAKE2b-256 checksum How to use checksums |
b659e265bbd23d565df0d19920584c6cd952f5a1579506535d263b03cb02e1cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for arguments 32
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.