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)
|
defaults = _format_defaults(opt)
|
||||||
for default_str in defaults:
|
for default_str in defaults:
|
||||||
if default_str:
|
if default_str:
|
||||||
default_str = ' ' + default_str
|
default_str = ' ' + default_str.replace('\n', '\n# ')
|
||||||
if minimal:
|
if minimal:
|
||||||
lines.append('%s =%s\n' % (opt.dest, default_str))
|
lines.append('%s =%s\n' % (opt.dest, default_str))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -122,6 +122,9 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||||
'str_opt_with_space': cfg.StrOpt('str_opt',
|
'str_opt_with_space': cfg.StrOpt('str_opt',
|
||||||
default=' foo bar ',
|
default=' foo bar ',
|
||||||
help='a string with spaces'),
|
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',
|
'bool_opt': cfg.BoolOpt('bool_opt',
|
||||||
default=False,
|
default=False,
|
||||||
help='a boolean'),
|
help='a boolean'),
|
||||||
|
@ -528,6 +531,19 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
# a string with spaces (string value)
|
# a string with spaces (string value)
|
||||||
#str_opt = " foo bar "
|
#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',
|
('bool_opt',
|
||||||
dict(opts=[('test', [(None, [opts['bool_opt']])])],
|
dict(opts=[('test', [(None, [opts['bool_opt']])])],
|
||||||
|
|
Loading…
Reference in New Issue