aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/coredata.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-04-04 13:51:26 -0700
committerDylan Baker <dylan@pnwbakers.com>2019-04-04 15:02:20 -0700
commit6940848f0bc9820d8f32667e4d0f9b73b68d2003 (patch)
tree51d0d7ca2410af56173e9342849f5ce62bcc3769 /mesonbuild/coredata.py
parentf8fcc7174d2c36d1fa1c91be52990ce600d806de (diff)
downloadmeson-6940848f0bc9820d8f32667e4d0f9b73b68d2003.zip
meson-6940848f0bc9820d8f32667e4d0f9b73b68d2003.tar.gz
meson-6940848f0bc9820d8f32667e4d0f9b73b68d2003.tar.bz2
coredata: Move argparse action getterin into BuiltinOption class
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r--mesonbuild/coredata.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 347af14..180f7e5 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -672,14 +672,6 @@ def get_builtin_option_description(optname):
else:
raise RuntimeError('Tried to get the description for an unknown builtin option \'%s\'.' % optname)
-def get_builtin_option_action(optname):
- default = builtin_options[optname].default
- if default is True:
- return 'store_false'
- elif default is False:
- return 'store_true'
- return None
-
def get_builtin_option_default(optname, prefix=''):
if optname in builtin_options:
o = builtin_options[optname]
@@ -700,9 +692,15 @@ def get_builtin_option_cmdline_name(name):
return '--' + name.replace('_', '-')
def add_builtin_argument(p, name):
+ try:
+ builtin = builtin_options[name]
+ except KeyError:
+ raise RuntimeError('Tried to get attribute of unknown builtin option "{}"'.format(name))
+
kwargs = {}
+
c = get_builtin_option_choices(name)
- b = get_builtin_option_action(name)
+ b = builtin.argparse_action()
h = get_builtin_option_description(name)
if not b:
h = h.rstrip('.') + ' (default: %s).' % get_builtin_option_default(name)
@@ -771,6 +769,13 @@ class BuiltinOption(Generic[_U]):
keywords['choices'] = self.choices
return self.opt_type(name, self.description, **keywords)
+ def argparse_action(self) -> Optional[str]:
+ if self.default is True:
+ return 'store_false'
+ elif self.default is False:
+ return 'store_true'
+ return None
+
builtin_options = {
'buildtype': BuiltinOption(UserComboOption, 'Build type to use', 'debug',