diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-04-04 14:25:09 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2019-04-04 15:02:20 -0700 |
commit | 1d7eda5fc8aef2938c9f66058fe706d98c32fa62 (patch) | |
tree | 8d799c230b843a206cf1d84de6d1d211cc361e9f /mesonbuild/coredata.py | |
parent | c3cb966631358ccb7e761c96c22b70ed631ff4de (diff) | |
download | meson-1d7eda5fc8aef2938c9f66058fe706d98c32fa62.zip meson-1d7eda5fc8aef2938c9f66058fe706d98c32fa62.tar.gz meson-1d7eda5fc8aef2938c9f66058fe706d98c32fa62.tar.bz2 |
coredata: Merge get_builtin_option_cmdline_name into BuiltinOption
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r-- | mesonbuild/coredata.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 69ac6a4..84e6136 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -654,12 +654,6 @@ def save(obj, build_dir): os.replace(tempfilename, filename) return filename -def get_builtin_option_cmdline_name(name): - if name == 'warning_level': - return '--warnlevel' - else: - return '--' + name.replace('_', '-') - def add_builtin_argument(p, name): try: builtin = builtin_options[name] @@ -680,7 +674,7 @@ def add_builtin_argument(p, name): kwargs['default'] = argparse.SUPPRESS kwargs['dest'] = name - cmdline_name = get_builtin_option_cmdline_name(name) + cmdline_name = builtin.argparse_name_to_arg(name) p.add_argument(cmdline_name, help=h, **kwargs) def register_builtin_arguments(parser): @@ -707,7 +701,7 @@ def parse_cmd_line_options(args): value = getattr(args, name, None) if value is not None: if name in args.cmd_line_options: - cmdline_name = get_builtin_option_cmdline_name(name) + cmdline_name = BuiltinOption.argparse_name_to_arg(name) raise MesonException( 'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name)) args.cmd_line_options[name] = value @@ -752,6 +746,13 @@ class BuiltinOption(Generic[_U]): return UserFeatureOption.static_choices return self.choices + @staticmethod + def argparse_name_to_arg(name: str) -> str: + if name == 'warning_level': + return '--warnlevel' + else: + return '--' + name.replace('_', '-') + def prefixed_default(self, name: str, prefix: str = '') -> Any: if self.opt_type in [UserComboOption, UserIntegerOption]: return self.default |