Argtools
Description
A collection of decorators wrapping argparse module for building command-line tools with minimal effort.
Quick start
Installation
$ pip install argtools
Building a simple command-line tool
# examples/test.py
from argtools import command, argument
@command
@argument('foo', help='a positional arugment')
@argument('--bar', default=3, help='an optional argument')
def main(args):
""" One line description here
Write details here (printed with --help|-h)
"""
print args.bar
print args.foo
return 1 # return code
if __name__ == '__main__':
command.run()
$ python test.py
$ python test.py -v # Increasing the verbosity of logging module
The argument decorator has the same api as argparse.ArgumentParser.add_argument.
See http://docs.python.org/dev/library/argparse.html for details.
Building subcommands
# examples/subtest.py
from argtools import command, argument
@command.add_sub
def foo(args):
""" This is foo
"""
print 'foo'
@command.add_sub
def bar(args):
""" This is bar
"""
print 'bar'
@command.add_sub(name=baz) # set different name
def bar(args):
""" This is baz
"""
print 'baz'
if __name__ == '__main__':
command.run()
$ python test.py foo # print foo
$ python test.py bar # print bar
$ python test.py bar -h # print help text of bar subcommand
Other features
- In
command.run(), the logging module is setup. You can control the verbosity with options: -v, -vv, .. - In
command.run(), SIGPIPE occured inside of wrapped function will be ignored to ease piping. - To use
grouporexclusivefunctionality of argparse, giveargumentobjects (e.g. arg1, arg2, arg3) as@argument.group(arg1, arg2, arg3)or@argument.exclusive(arg1, arg2, arg3), respectively (documentation is #TODO). - Builtin options: -v, --verbose and --debug can be turned off by setting
command.add_verbose = Falseorcommand.add_debug = False
Metadata
Release files for argtools 0.1.6
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 |
|---|---|---|---|---|
| argtools-0.1.6.tar.gz | 4.8 kB | Without provenance | Details for argtools-0.1.6.tar.gz |
Release files / argtools-0.1.6.tar.gz
| Download URL | argtools-0.1.6.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d5f9be15a81822fe53b05a8e73983267929c55fb65751506c97425b0557bbec
|
|
BLAKE2b-256 checksum How to use checksums |
cc6e697dcd8daaa1c47fd4c72419112664c6b7c10af069340390b5932a97ebdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.0
|
Security for argtools 0.1.6
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.