Print choices in the config generator
One more stop-gap till we move Nova to oslo-config-generator. Copy a bit of code to print the Allowed values in a StrOpt's choices field. Change-Id: I1ba69084e385fccbb54321a50500604393f886be
This commit is contained in:
parent
420931abd5
commit
42ad8b0356
|
@ -241,6 +241,14 @@ def _sanitize_default(name, value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def _get_choice_text(choice):
|
||||||
|
if choice is None:
|
||||||
|
return '<None>'
|
||||||
|
elif choice == '':
|
||||||
|
return "''"
|
||||||
|
return six.text_type(choice)
|
||||||
|
|
||||||
|
|
||||||
def _print_opt(opt):
|
def _print_opt(opt):
|
||||||
opt_name, opt_default, opt_help = opt.dest, opt.default, opt.help
|
opt_name, opt_default, opt_help = opt.dest, opt.default, opt.help
|
||||||
if not opt_help:
|
if not opt_help:
|
||||||
|
@ -268,6 +276,11 @@ def _print_opt(opt):
|
||||||
print('#%s=<None>' % opt_name)
|
print('#%s=<None>' % opt_name)
|
||||||
elif opt_type == STROPT:
|
elif opt_type == STROPT:
|
||||||
assert(isinstance(opt_default, six.string_types))
|
assert(isinstance(opt_default, six.string_types))
|
||||||
|
if (getattr(opt, 'type', None) and
|
||||||
|
getattr(opt.type, 'choices', None)):
|
||||||
|
choices_text = ', '.join([_get_choice_text(choice)
|
||||||
|
for choice in opt.type.choices])
|
||||||
|
print('# Allowed values: %s' % choices_text)
|
||||||
print('#%s=%s' % (opt_name, _sanitize_default(opt_name,
|
print('#%s=%s' % (opt_name, _sanitize_default(opt_name,
|
||||||
opt_default)))
|
opt_default)))
|
||||||
elif opt_type == BOOLOPT:
|
elif opt_type == BOOLOPT:
|
||||||
|
|
Loading…
Reference in New Issue