[svn r63353] better command option handling

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-26 13:21:05 +01:00
parent 9b5e15bebe
commit cd3e86d185
2 changed files with 5 additions and 3 deletions

View File

@ -20,7 +20,7 @@ class Parser:
""" Parser for command line arguments. """
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._processopt = processopt
self._usage = usage
@ -50,7 +50,9 @@ class Parser:
def parse(self, args):
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:
desc = group.description or group.name
optgroup = optparse.OptionGroup(optparser, desc)

View File

@ -38,7 +38,7 @@ class TestParser:
def test_parser_addoption(self):
parser = parseopt.Parser()
group = parser.getgroup("misc")
group = parser.getgroup("custom options")
assert len(group.options) == 0
group.addoption("--option1", action="store_true")
assert len(group.options) == 1