Use decorators for dealing with argparse
Project description
Installation
pip install decparse
Usage
Before with argeparse
import argparse
parser = argparse.ArgumentParser(
prog='foo',
description='Print bar',
add_help=True
)
parser.add_argument(
'--baz',
action='store_true'
help='Also print baz'
)
args = parser.parse_arguments()
print('bar')
if args.baz:
print('baz')
Using decopts instead
from decopts import entrypoint, option
@entrypoint(
prog='foo',
description='Print bar',
add_help=True
)
@option(
'--baz',
action='store_true'
help='Also print baz'
)
def main():
print('bar')
if main.args.baz:
print('baz')
main()
Adding subcommands
from decopts import entrypoint, option, action
@entrypoint(
prog='foo',
description='Print something',
add_help=True
)
def main():
return
@action(
main,
'foo',
description='Print foo'
)
def foo():
print('foo')
@action(
main,
'baz',
description='Print baz'
)
def baz():
print('baz')
main()
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
decopts-1.0.1.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for decopts-1.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 041ebedd2fb2255be880d51883702e77bceeade4bae1a8bd3bf8d9951406f58f |
|
MD5 | 5b1a53e4e19540a54af9c0512824b141 |
|
BLAKE2b-256 | d0982340e4d72aa8391492e25cbe8953c92843fd838d3ed1be2860b2e71c077b |