No description, website, or topics provided.
Python Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
subarg
tests
.editorconfig
.gitignore
.travis.yml
LICENSE
Makefile
README.md
requirements-dev.txt
setup.cfg
setup.py

README.md

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