coredata: Merge get_builtin_option_cmdline_name into BuiltinOption

pull/4931/head
Dylan Baker 6 years ago
parent c3cb966631
commit 1d7eda5fc8
  1. 17
      mesonbuild/coredata.py

@ -654,12 +654,6 @@ def save(obj, build_dir):
os.replace(tempfilename, filename) os.replace(tempfilename, filename)
return 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): def add_builtin_argument(p, name):
try: try:
builtin = builtin_options[name] builtin = builtin_options[name]
@ -680,7 +674,7 @@ def add_builtin_argument(p, name):
kwargs['default'] = argparse.SUPPRESS kwargs['default'] = argparse.SUPPRESS
kwargs['dest'] = name 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) p.add_argument(cmdline_name, help=h, **kwargs)
def register_builtin_arguments(parser): def register_builtin_arguments(parser):
@ -707,7 +701,7 @@ def parse_cmd_line_options(args):
value = getattr(args, name, None) value = getattr(args, name, None)
if value is not None: if value is not None:
if name in args.cmd_line_options: 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( raise MesonException(
'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name)) 'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name))
args.cmd_line_options[name] = value args.cmd_line_options[name] = value
@ -752,6 +746,13 @@ class BuiltinOption(Generic[_U]):
return UserFeatureOption.static_choices return UserFeatureOption.static_choices
return self.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: def prefixed_default(self, name: str, prefix: str = '') -> Any:
if self.opt_type in [UserComboOption, UserIntegerOption]: if self.opt_type in [UserComboOption, UserIntegerOption]:
return self.default return self.default

Loading…
Cancel
Save