Add type information to parser for command line arguments

This commit is contained in:
Kovid Goyal 2009-06-25 09:11:23 -07:00
parent e65d1325f8
commit f65151caaa

View File

@ -70,11 +70,18 @@ def option_recommendation_to_cli_option(add_option, rec):
switches.append('--'+opt.long_switch) switches.append('--'+opt.long_switch)
attrs = dict(dest=opt.name, help=opt.help, attrs = dict(dest=opt.name, help=opt.help,
choices=opt.choices, default=rec.recommended_value) choices=opt.choices, default=rec.recommended_value)
if opt.long_switch == 'verbose':
attrs['action'] = 'count'
if isinstance(rec.recommended_value, type(True)): if isinstance(rec.recommended_value, type(True)):
attrs['action'] = 'store_false' if rec.recommended_value else \ attrs['action'] = 'store_false' if rec.recommended_value else \
'store_true' 'store_true'
else:
if isinstance(rec.recommended_value, int):
attrs['type'] = 'int'
if isinstance(rec.recommended_value, float):
attrs['type'] = 'float'
if opt.long_switch == 'verbose':
attrs['action'] = 'count'
attrs.pop('type', '')
add_option(Option(*switches, **attrs)) add_option(Option(*switches, **attrs))
def add_input_output_options(parser, plumber): def add_input_output_options(parser, plumber):