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:
@ -51,10 +51,12 @@ jc changelog
|
|||||||
`/proc/<pid>/stat`
|
`/proc/<pid>/stat`
|
||||||
`/proc/<pid>/statm`
|
`/proc/<pid>/statm`
|
||||||
`/proc/<pid>/status`
|
`/proc/<pid>/status`
|
||||||
|
- Magic syntax support for `/proc` files
|
||||||
- Enhance `free` parser to support `-w` option integer conversions
|
- Enhance `free` parser to support `-w` option integer conversions
|
||||||
- Fix `ini` and `kv` parsers so they don't change keynames to lower case
|
- Fix `ini` and `kv` parsers so they don't change keynames to lower case
|
||||||
NOTE: This can be a breaking change in your scripts
|
NOTE: This can be a breaking change in your scripts
|
||||||
- Fix `id` command parser to allow usernames and groupnames with spaces
|
- 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 tests
|
||||||
- Optimize documentation build script
|
- Optimize documentation build script
|
||||||
|
|
||||||
|
@ -475,6 +475,10 @@ def add_metadata_to(list_or_dict,
|
|||||||
does not already exist, it will be created with the metadata fields. If
|
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 _jc_meta field already exists, the metadata fields will be added to
|
||||||
the existing object.
|
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()
|
run_timestamp = runtime.timestamp()
|
||||||
|
|
||||||
@ -494,6 +498,9 @@ def add_metadata_to(list_or_dict,
|
|||||||
list_or_dict['_jc_meta'].update(meta_obj)
|
list_or_dict['_jc_meta'].update(meta_obj)
|
||||||
|
|
||||||
elif isinstance(list_or_dict, list):
|
elif isinstance(list_or_dict, list):
|
||||||
|
if not list_or_dict:
|
||||||
|
list_or_dict.append({})
|
||||||
|
|
||||||
for item in list_or_dict:
|
for item in list_or_dict:
|
||||||
if '_jc_meta' not in item:
|
if '_jc_meta' not in item:
|
||||||
item['_jc_meta'] = {}
|
item['_jc_meta'] = {}
|
||||||
|
Reference in New Issue
Block a user