From: Zac Medico Date: Fri, 2 Aug 2013 18:03:49 +0000 (-0700) Subject: _argparse: support add_argument_group X-Git-Tag: v2.2.0_alpha192~20 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bfdc03077c6b85df207c6109a57a7af7d5e5676a;p=portage.git _argparse: support add_argument_group --- diff --git a/pym/portage/util/_argparse.py b/pym/portage/util/_argparse.py index 4227f4c47..a44afed7b 100644 --- a/pym/portage/util/_argparse.py +++ b/pym/portage/util/_argparse.py @@ -7,7 +7,7 @@ try: from argparse import ArgumentParser except ImportError: # Compatibility with Python 2.6 and 3.1 - from optparse import OptionParser + from optparse import OptionGroup, OptionParser class ArgumentParser(object): def __init__(self, **kwargs): @@ -15,6 +15,16 @@ except ImportError: if add_help is not None: kwargs["add_help_option"] = add_help parser = OptionParser(**kwargs) + self._parser = parser self.add_argument = parser.add_option self.parse_known_args = parser.parse_args self.parse_args = parser.parse_args + + def add_argument_group(self, title=None, **kwargs): + optiongroup = OptionGroup(self._parser, title, **kwargs) + self._parser.add_option_group(optiongroup) + return _ArgumentGroup(optiongroup) + + class _ArgumentGroup(object): + def __init__(self, optiongroup): + self.add_argument = optiongroup.add_option