coredata: Add helper for setting action

Currently we manually pass the argparse action, this isn't very DRY,
since the builtin_types already has all the data necessary to find that.
This adds a new function to determine the action based on the default
type.
pull/3243/head
Dylan Baker 7 years ago
parent 33c5c7e7e9
commit bbf71d9aa3
  1. 8
      mesonbuild/coredata.py
  2. 12
      mesonbuild/mesonmain.py

@ -359,6 +359,14 @@ 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][2]
if default is True:
return 'store_false'
elif default is False:
return 'store_true'
return None
def get_builtin_option_default(optname, prefix='', noneIfSuppress=False):
if is_builtin_option(optname):
o = builtin_options[optname]

@ -28,10 +28,12 @@ default_warning = '1'
def add_builtin_argument(p, name, **kwargs):
k = kwargs.get('dest', name.replace('-', '_'))
c = coredata.get_builtin_option_choices(k)
b = kwargs.get('action', None) in ['store_true', 'store_false']
b = coredata.get_builtin_option_action(k)
h = coredata.get_builtin_option_description(k)
if not b:
h = h.rstrip('.') + ' (default: %s).' % coredata.get_builtin_option_default(k)
else:
kwargs['action'] = b
if c and not b:
kwargs['choices'] = c
default = coredata.get_builtin_option_default(k, noneIfSuppress=True)
@ -58,14 +60,14 @@ def create_parser():
add_builtin_argument(p, 'sharedstatedir')
add_builtin_argument(p, 'backend')
add_builtin_argument(p, 'buildtype')
add_builtin_argument(p, 'strip', action='store_true')
add_builtin_argument(p, 'strip')
add_builtin_argument(p, 'unity')
add_builtin_argument(p, 'werror', action='store_true')
add_builtin_argument(p, 'werror')
add_builtin_argument(p, 'layout')
add_builtin_argument(p, 'default-library')
add_builtin_argument(p, 'warnlevel', dest='warning_level')
add_builtin_argument(p, 'stdsplit', action='store_false')
add_builtin_argument(p, 'errorlogs', action='store_false')
add_builtin_argument(p, 'stdsplit')
add_builtin_argument(p, 'errorlogs')
p.add_argument('--cross-file', default=None,
help='File describing cross compilation environment.')
p.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option",

Loading…
Cancel
Save