[svn r63353] better command option handling
--HG-- branch : trunk
This commit is contained in:
parent
9b5e15bebe
commit
cd3e86d185
|
@ -20,7 +20,7 @@ class Parser:
|
||||||
""" Parser for command line arguments. """
|
""" Parser for command line arguments. """
|
||||||
|
|
||||||
def __init__(self, usage=None, processopt=None):
|
def __init__(self, usage=None, processopt=None):
|
||||||
self._anonymous = OptionGroup("misc", parser=self)
|
self._anonymous = OptionGroup("custom options", parser=self)
|
||||||
self._groups = [self._anonymous]
|
self._groups = [self._anonymous]
|
||||||
self._processopt = processopt
|
self._processopt = processopt
|
||||||
self._usage = usage
|
self._usage = usage
|
||||||
|
@ -50,7 +50,9 @@ class Parser:
|
||||||
|
|
||||||
def parse(self, args):
|
def parse(self, args):
|
||||||
optparser = optparse.OptionParser(usage=self._usage)
|
optparser = optparse.OptionParser(usage=self._usage)
|
||||||
for group in self._groups:
|
# make sure anaonymous group is at the end
|
||||||
|
groups = self._groups[1:] + [self._groups[0]]
|
||||||
|
for group in groups:
|
||||||
if group.options:
|
if group.options:
|
||||||
desc = group.description or group.name
|
desc = group.description or group.name
|
||||||
optgroup = optparse.OptionGroup(optparser, desc)
|
optgroup = optparse.OptionGroup(optparser, desc)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestParser:
|
||||||
|
|
||||||
def test_parser_addoption(self):
|
def test_parser_addoption(self):
|
||||||
parser = parseopt.Parser()
|
parser = parseopt.Parser()
|
||||||
group = parser.getgroup("misc")
|
group = parser.getgroup("custom options")
|
||||||
assert len(group.options) == 0
|
assert len(group.options) == 0
|
||||||
group.addoption("--option1", action="store_true")
|
group.addoption("--option1", action="store_true")
|
||||||
assert len(group.options) == 1
|
assert len(group.options) == 1
|
||||||
|
|
Loading…
Reference in New Issue