Handle multi-line default values in olso-config-generator
The oslo.config file format permits multi-line values for options, however all the lines except for the first one need to be indented. Right now oslo-config-generator fails to take that into account, and instead outputs the formatted value as is, adding a comment character only to the first line, and not commenting out or indenting the subsequent lines. This patch tries to fix that by adding a comment character and some indentation to every newline in the formatted value. Change-Id: I33381c8cfb59901ce6dfc07bd662f2edb56531dd Closes-bug: #1689594
This commit is contained in:
parent
0b0200572d
commit
47d7c1c090
|
@ -311,7 +311,7 @@ class _OptFormatter(object):
|
|||
defaults = _format_defaults(opt)
|
||||
for default_str in defaults:
|
||||
if default_str:
|
||||
default_str = ' ' + default_str
|
||||
default_str = ' ' + default_str.replace('\n', '\n# ')
|
||||
if minimal:
|
||||
lines.append('%s =%s\n' % (opt.dest, default_str))
|
||||
else:
|
||||
|
|
|
@ -122,6 +122,9 @@ class GeneratorTestCase(base.BaseTestCase):
|
|||
'str_opt_with_space': cfg.StrOpt('str_opt',
|
||||
default=' foo bar ',
|
||||
help='a string with spaces'),
|
||||
'str_opt_multiline': cfg.StrOpt('str_opt',
|
||||
default='foo\nbar\nbaz',
|
||||
help='a string with newlines'),
|
||||
'bool_opt': cfg.BoolOpt('bool_opt',
|
||||
default=False,
|
||||
help='a boolean'),
|
||||
|
@ -528,6 +531,19 @@ class GeneratorTestCase(base.BaseTestCase):
|
|||
|
||||
# a string with spaces (string value)
|
||||
#str_opt = " foo bar "
|
||||
''')),
|
||||
('str_opt_multiline',
|
||||
dict(opts=[('test', [(None, [opts['str_opt_multiline']])])],
|
||||
expected='''[DEFAULT]
|
||||
|
||||
#
|
||||
# From test
|
||||
#
|
||||
|
||||
# a string with newlines (string value)
|
||||
#str_opt = foo
|
||||
# bar
|
||||
# baz
|
||||
''')),
|
||||
('bool_opt',
|
||||
dict(opts=[('test', [(None, [opts['bool_opt']])])],
|
||||
|
|
Loading…
Reference in New Issue