summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-07 23:36:33 +0000
committerGerrit Code Review <review@openstack.org>2015-03-07 23:36:33 +0000
commit1e42eb8f40eae29dd062d40b53ad37e908d7e72f (patch)
tree993be5da0134abf17853606fc9d544073eb23e85
parentaefb53bc92fdc4def25459acae1bd4781a107616 (diff)
parent0f550d7c79249900c7f23fdd53723a1f2443e01d (diff)
downloadoslo-config-1e42eb8f40eae29dd062d40b53ad37e908d7e72f.tar.gz
Merge "Generate help text indicating possible values"1.9.1
-rw-r--r--oslo_config/generator.py4
-rw-r--r--oslo_config/tests/test_generator.py16
-rw-r--r--tests/test_generator.py16
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]