1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

Add metadata object to empty results list

This commit is contained in:
Kelly Brazil
2022-09-27 11:11:16 -07:00
parent 086cdc559c
commit 03a2b35846
2 changed files with 9 additions and 0 deletions

View File

@ -51,10 +51,12 @@ jc changelog
`/proc/<pid>/stat`
`/proc/<pid>/statm`
`/proc/<pid>/status`
- Magic syntax support for `/proc` files
- Enhance `free` parser to support `-w` option integer conversions
- Fix `ini` and `kv` parsers so they don't change keynames to lower case
NOTE: This can be a breaking change in your scripts
- Fix `id` command parser to allow usernames and groupnames with spaces
- Enhance metadata output to output metadata even when results are empty
- Optimize tests
- Optimize documentation build script

View File

@ -475,6 +475,10 @@ def add_metadata_to(list_or_dict,
does not already exist, it will be created with the metadata fields. If
the _jc_meta field already exists, the metadata fields will be added to
the existing object.
In the case of an empty list (no data), a dictionary with a _jc_meta
object will be added to the list. This way you always get metadata,
even if there are no results.
"""
run_timestamp = runtime.timestamp()
@ -494,6 +498,9 @@ def add_metadata_to(list_or_dict,
list_or_dict['_jc_meta'].update(meta_obj)
elif isinstance(list_or_dict, list):
if not list_or_dict:
list_or_dict.append({})
for item in list_or_dict:
if '_jc_meta' not in item:
item['_jc_meta'] = {}