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

history parser fixes

This commit is contained in:
Kelly Brazil
2019-10-24 17:33:42 -07:00
parent 08ec21556b
commit 85bfb68886
2 changed files with 15 additions and 10 deletions

View File

@ -162,10 +162,10 @@ $ free | jc --free -p
``` ```
$ history | jc --history -p $ history | jc --history -p
{ {
"118": "sleep 100", "n118": "sleep 100",
"119": "ls /bin", "n119": "ls /bin",
"120": "echo \"hello\"", "n120": "echo \"hello\"",
"121": "docker images", "n121": "docker images",
... ...
} }
``` ```

View File

@ -7,10 +7,10 @@ Example:
$ history | jc --history -p $ history | jc --history -p
{ {
"118": "sleep 100", "n118": "sleep 100",
"119": "ls /bin", "n119": "ls /bin",
"120": "echo \"hello\"", "n120": "echo \"hello\"",
"121": "docker images", "n121": "docker images",
... ...
} }
""" """
@ -26,7 +26,12 @@ def parse(data):
if cleandata: if cleandata:
for entry in cleandata: for entry in cleandata:
try:
parsed_line = entry.split(maxsplit=1) parsed_line = entry.split(maxsplit=1)
output[parsed_line[0]] = parsed_line[1] # prepend a alpha character n to be more json compliant
output['n' + parsed_line[0]] = parsed_line[1]
except IndexError:
# need to catch indexerror in case there is weird input from prior commands
pass
return output return output