diff options
-rw-r--r-- | oslo_config/generator.py | 4 | ||||
-rw-r--r-- | oslo_config/tests/test_generator.py | 16 | ||||
-rw-r--r-- | tests/test_generator.py | 16 |
3 files changed, 36 insertions, 0 deletions
diff --git a/oslo_config/generator.py b/oslo_config/generator.py index 17977c2..0a4f7ce 100644 --- a/oslo_config/generator.py +++ b/oslo_config/generator.py @@ -193,6 +193,10 @@ class _OptFormatter(object): help_text = u'(%s)' % opt_type lines = self._format_help(help_text) + if getattr(opt.type, 'choices', None): + choices_text = ', '.join(opt.type.choices) + lines.append('# Allowed values: %s\n' % choices_text) + for d in opt.deprecated_opts: lines.append('# Deprecated group/name - [%s]/%s\n' % (d.group or 'DEFAULT', d.name or opt.dest)) diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index 5922fb4..afd500f 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -48,6 +48,10 @@ class GeneratorTestCase(base.BaseTestCase): 'cupidatat non proident, sunt in culpa ' 'qui officia deserunt mollit anim id est ' 'laborum.'), + 'choices_opt': cfg.StrOpt('choices_opt', + default='a', + choices=('a', 'b', 'c'), + help='a string with choices'), 'deprecated_opt': cfg.StrOpt('bar', deprecated_name='foobar', help='deprecated'), @@ -281,6 +285,18 @@ class GeneratorTestCase(base.BaseTestCase): ''' #long_help = <None> ''')), + ('choices_opt', + dict(opts=[('test', [(None, [opts['choices_opt']])])], + expected='''[DEFAULT] + +# +# From test +# + +# a string with choices (string value) +# Allowed values: a, b, c +#choices_opt = a +''')), ('deprecated', dict(opts=[('test', [('foo', [opts['deprecated_opt']])])], expected='''[DEFAULT] diff --git a/tests/test_generator.py b/tests/test_generator.py index 6717da0..41ddfec 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -52,6 +52,10 @@ class GeneratorTestCase(base.BaseTestCase): 'cupidatat non proident, sunt in culpa ' 'qui officia deserunt mollit anim id est ' 'laborum.'), + 'choices_opt': cfg.StrOpt('choices_opt', + default='a', + choices=('a', 'b', 'c'), + help='a string with choices'), 'deprecated_opt': cfg.StrOpt('bar', deprecated_name='foobar', help='deprecated'), @@ -296,6 +300,18 @@ class GeneratorTestCase(base.BaseTestCase): ''' #long_help = <None> ''')), + ('choices_opt', + dict(opts=[('test', [(None, [opts['choices_opt']])])], + expected='''[DEFAULT] + +# +# From test +# + +# a string with choices (string value) +# Allowed values: a, b, c +#choices_opt = a +''')), ('deprecated', dict(opts=[('test', [('foo', [opts['deprecated_opt']])])], expected='''[DEFAULT] |