summary: Add list_sep keyword argument
This allows having lists on a single line instead of having each value aligned on a new line.
This commit is contained in:
parent
f66b04b099
commit
c175e97a88
|
@ -1239,9 +1239,10 @@ pair doesn't appear twice. All sections will be collected and printed at
|
|||
the end of the configuration in the same order as they have been called.
|
||||
|
||||
Keyword arguments:
|
||||
- `section` title to group a set of key/value pairs.
|
||||
- `bool_yn` if set to true, all boolean values will be replaced by green YES
|
||||
or red NO.
|
||||
- `section` title to group a set of key/value pairs.
|
||||
- `list_sep` *Since 0.54.0* string used to separate list values (e.g. `', '`).
|
||||
|
||||
Example:
|
||||
```meson
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
## Summary improvements
|
||||
|
||||
A new `list_sep` keyword argument has been added to `summary()` function.
|
||||
If defined and the value is a list, elements will be separated by the provided
|
||||
string instead of being aligned on a new line.
|
|
@ -1791,6 +1791,9 @@ class Summary:
|
|||
bool_yn = kwargs.get('bool_yn', False)
|
||||
if not isinstance(bool_yn, bool):
|
||||
raise InterpreterException('bool_yn keyword argument must be boolean')
|
||||
list_sep = kwargs.get('list_sep')
|
||||
if list_sep is not None and not isinstance(list_sep, str):
|
||||
raise InterpreterException('list_sep keyword argument must be string')
|
||||
for k, v in values.items():
|
||||
if k in self.sections[section]:
|
||||
raise InterpreterException('Summary section {!r} already have key {!r}'.format(section, k))
|
||||
|
@ -1803,9 +1806,7 @@ class Summary:
|
|||
formatted_values.append(mlog.green('YES') if i else mlog.red('NO'))
|
||||
else:
|
||||
formatted_values.append(i)
|
||||
if not formatted_values:
|
||||
formatted_values = ['']
|
||||
self.sections[section][k] = formatted_values
|
||||
self.sections[section][k] = (formatted_values, list_sep)
|
||||
self.max_key_len = max(self.max_key_len, len(k))
|
||||
|
||||
def dump(self):
|
||||
|
@ -1815,11 +1816,14 @@ class Summary:
|
|||
if section:
|
||||
mlog.log(' ', mlog.bold(section))
|
||||
for k, v in values.items():
|
||||
v, list_sep = v
|
||||
indent = self.max_key_len - len(k) + 3
|
||||
mlog.log(' ' * indent, k + ':', v[0])
|
||||
indent = self.max_key_len + 5
|
||||
for i in v[1:]:
|
||||
mlog.log(' ' * indent, i)
|
||||
end = ' ' if v else ''
|
||||
mlog.log(' ' * indent, k + ':', end=end)
|
||||
if list_sep is None:
|
||||
indent = self.max_key_len + 6
|
||||
list_sep = '\n' + ' ' * indent
|
||||
mlog.log(*v, sep=list_sep)
|
||||
mlog.log('') # newline
|
||||
|
||||
|
||||
|
@ -2949,7 +2953,8 @@ external dependencies (including libraries) must go to "dependencies".''')
|
|||
mlog.log(mlog.bold('Message:'), *args)
|
||||
|
||||
@noArgsFlattening
|
||||
@permittedKwargs({'section', 'bool_yn'})
|
||||
@FeatureNewKwargs('summary', '0.54.0', ['list_sep'])
|
||||
@permittedKwargs({'section', 'bool_yn', 'list_sep'})
|
||||
@FeatureNew('summary', '0.53.0')
|
||||
def func_summary(self, node, args, kwargs):
|
||||
if len(args) == 1:
|
||||
|
|
|
@ -4347,10 +4347,11 @@ recommended as it is not supported on some platforms''')
|
|||
A list: string
|
||||
1
|
||||
True
|
||||
empty list:
|
||||
empty list:
|
||||
A number: 1
|
||||
yes: YES
|
||||
no: NO
|
||||
coma list: a, b, c
|
||||
|
||||
Subprojects
|
||||
sub: YES
|
||||
|
|
|
@ -12,3 +12,4 @@ summary({'Some boolean': false,
|
|||
summary('A number', 1, section: 'Configuration')
|
||||
summary('yes', true, bool_yn : true, section: 'Configuration')
|
||||
summary('no', false, bool_yn : true, section: 'Configuration')
|
||||
summary('coma list', ['a', 'b', 'c'], list_sep: ', ', section: 'Configuration')
|
||||
|
|
Loading…
Reference in New Issue