Skip to content

Commit

Permalink
Generate help text indicating possible values
Browse files Browse the repository at this point in the history
Since the introduction of choices, the help text does not indicate
possible values of these choices.  This patch adds to the help a
list of all values that are accepted.

Change-Id: I68edda59ad7a690918f8e45abe2b3b56cd01ada7
Closes-Bug: 1427913
  • Loading branch information
ericwb committed Mar 5, 2015
1 parent d1ccc43 commit 0f550d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions oslo_config/generator.py
Expand Up @@ -193,6 +193,10 @@ def format(self, opt):
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))
Expand Down
16 changes: 16 additions & 0 deletions oslo_config/tests/test_generator.py
Expand Up @@ -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'),
Expand Down Expand Up @@ -280,6 +284,18 @@ class GeneratorTestCase(base.BaseTestCase):
'(string value)'
'''
#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']])])],
Expand Down
16 changes: 16 additions & 0 deletions tests/test_generator.py
Expand Up @@ -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'),
Expand Down Expand Up @@ -295,6 +299,18 @@ class GeneratorTestCase(base.BaseTestCase):
'(string value)'
'''
#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']])])],
Expand Down

0 comments on commit 0f550d7

Please sign in to comment.