1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

append duplicate key values to original key instead of adding unique keys

This commit is contained in:
Kelly Brazil
2020-07-09 16:25:41 -07:00
parent c6baf42e72
commit dd98eb1ec8

View File

@ -104,7 +104,6 @@ def parse(data, raw=False, quiet=False):
if not quiet: if not quiet:
jc.utils.compatibility(__name__, info.compatible) jc.utils.compatibility(__name__, info.compatible)
tail = 0
raw_output = {} raw_output = {}
if jc.utils.has_data(data): if jc.utils.has_data(data):
@ -121,14 +120,12 @@ def parse(data, raw=False, quiet=False):
key = linedata[0] key = linedata[0]
value = linedata[1].lstrip() value = linedata[1].lstrip()
# syctl -a repeats some keys on linux. need to make new keys unique if # syctl -a repeats some keys on linux. Append values from repeating keys
# they already exist so we don't lose data. # to the previous key value
if key in raw_output: if key in raw_output:
tail += 1 existing_value = raw_output[key]
key = f'{key}_{tail}' raw_output[key] = existing_value + '\n' + value
raw_output[key] = value
else: else:
tail = 0
raw_output[key] = value raw_output[key] = value
if raw: if raw: