subarg
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']]
argparse
Collaborate with 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