subarg

Parse sub-arguments in `[` and `]` recursively


License
MIT
Install
pip install subarg==1.0.1

Documentation

subarg

License Python PyPI Travis CI Coverage Status

Parse sub-arguments in [ and ] recursively.

Usage

Basically

>>> import subarg
>>> argv = ['--foo', 'bar', '--buz', '[', 'qux', '--quux', 'corge', ']']
>>> subarg.parse(argv)
['--foo', 'bar', '--buz', ['qux', '--quux', 'corge']]

It's useful to pass sys.argv directly. For example, with example.py like

import sys
import subarg

args = subarg.parse(sys.argv)

print(args)

and execute belows, then arguments would be parsed like

% python example.py --foo bar --buz [ qux --quux corge ]
['example.py', '--foo', 'bar', '--buz', ['qux', '--quux', 'corge']]

Collaborate with argparse

We can collaborate with argparse.

import sys
import subarg
from argparse import ArgumentParser

sys.argv = subarg.parse(sys.argv)

parser = ArgumentParser()
parser.add_argument('--foo')
parser.add_argument('--buz')
args = parser.parse_args()

print(args)

Then

% python example.py --foo bar --buz [ qux --quux corge ]
Namespace(buz=['qux', '--quux', 'corge'], foo='bar')

Test

make test

License

MIT (c) keik