mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add route parser
This commit is contained in:
3
jc/jc.py
3
jc/jc.py
@ -10,6 +10,7 @@ import jc.parsers.ifconfig
|
|||||||
import jc.parsers.ls
|
import jc.parsers.ls
|
||||||
import jc.parsers.netstat
|
import jc.parsers.netstat
|
||||||
import jc.parsers.ps
|
import jc.parsers.ps
|
||||||
|
import jc.parsers.route
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -37,6 +38,8 @@ def main():
|
|||||||
result = jc.parsers.netstat.parse(data)
|
result = jc.parsers.netstat.parse(data)
|
||||||
elif arg == '--ps':
|
elif arg == '--ps':
|
||||||
result = jc.parsers.ps.parse(data)
|
result = jc.parsers.ps.parse(data)
|
||||||
|
elif arg == '--route':
|
||||||
|
result = jc.parsers.route.parse(data)
|
||||||
|
|
||||||
# output resulting dictionary as json
|
# output resulting dictionary as json
|
||||||
if pretty:
|
if pretty:
|
||||||
|
21
jc/parsers/route.py
Normal file
21
jc/parsers/route.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"""jc - JSON CLI output utility route Parser
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
specify --route as the first argument if the piped input is coming from route
|
||||||
|
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def parse(data):
|
||||||
|
|
||||||
|
# code adapted from Conor Heine at:
|
||||||
|
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
|
||||||
|
|
||||||
|
cleandata = data.splitlines()
|
||||||
|
headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h]
|
||||||
|
raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:])
|
||||||
|
return [dict(zip(headers, r)) for r in raw_data]
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='jc',
|
name='jc',
|
||||||
version='0.5.1',
|
version='0.5.2',
|
||||||
author='Kelly Brazil',
|
author='Kelly Brazil',
|
||||||
author_email='kellyjonbrazil@gmail.com',
|
author_email='kellyjonbrazil@gmail.com',
|
||||||
description='This tool serializes the output of popular command line tools to structured JSON output.',
|
description='This tool serializes the output of popular command line tools to structured JSON output.',
|
||||||
|
Reference in New Issue
Block a user