diff options
author | comex | 2015-08-07 17:08:01 -0400 |
---|---|---|
committer | comex | 2015-08-07 17:08:37 -0400 |
commit | dab0e58f40c927a57e2bec6c29bef32a09275ee4 (patch) | |
tree | 886416a99ac4b2c2894872095af4b43366a67e61 /script/mconfig.py | |
parent | fixes (diff) | |
download | substitute-dab0e58f40c927a57e2bec6c29bef32a09275ee4.tar.gz |
add the missing ability to specify --disable-x and --without-x ;p
Diffstat (limited to '')
-rw-r--r-- | script/mconfig.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/script/mconfig.py b/script/mconfig.py index 4afccad..179218c 100644 --- a/script/mconfig.py +++ b/script/mconfig.py @@ -226,7 +226,7 @@ class OptSection(object): all_opt_sections.append(self) class Option(object): - def __init__(self, name, help, on_set, default=None, bool=False, show=True, section=None, metavar=None, type=str, **kwargs): + def __init__(self, name, help, on_set, default=None, bool=False, opposite=None, show=True, section=None, metavar=None, type=str, **kwargs): if name.startswith('--'): self.is_env = False assert set(kwargs).issubset({'nargs', 'choices', 'required', 'metavar'}) @@ -246,6 +246,15 @@ class Option(object): metavar = '...' self.metavar = metavar self.bool = bool + if bool: + if opposite is None: + if name.startswith('--enable-'): + opposite = '--disable-' + name[9:] + elif name.startswith('--with-'): + opposite = '--without-' + name[7:] + else: + raise ValueError("need opposite for bool option %r" %(name,)) + self.opposite = opposite self.section = section if section is not None else default_opt_section self.section.opts.append(self) self.argparse_kw = kwargs.copy() @@ -379,6 +388,11 @@ def _make_argparse(include_unused, include_env): dest=opt.name[2:], help=opt.help, **kw) + if opt.bool and include_unused: + ag.add_argument(opt.opposite, + action='store_false', + dest=opt.name[2:], + **kw) return parser def _print_help(include_unused=False): |