From fa7466022bb8947c1bbf9f7b01aa4d92300a8992 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 24 Oct 2019 15:54:31 -0700 Subject: [PATCH] fix env parser --- README.md | 37 +++++++++++-------------------------- changelog.txt | 3 +++ jc/parsers/env.py | 44 ++++++++++++++------------------------------ 3 files changed, 28 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 98d9a00f..068882ad 100755 --- a/README.md +++ b/README.md @@ -122,32 +122,17 @@ $ df | jc --df -p ### env ``` $ env | jc --env -p -[ - { - "TERM": "xterm-256color" - }, - { - "SHELL": "/bin/bash" - }, - { - "USER": "root" - }, - { - "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" - }, - { - "PWD": "/bin" - }, - { - "LANG": "en_US.UTF-8" - }, - { - "HOME": "/root" - }, - { - "_": "/usr/bin/env" - } -] +{ + "TERM": "xterm-256color", + "SHELL": "/bin/bash", + "USER": "root", + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PWD": "/root", + "LANG": "en_US.UTF-8", + "HOME": "/root", + "LOGNAME": "root", + "_": "/usr/bin/env" +} ``` ### ifconfig ``` diff --git a/changelog.txt b/changelog.txt index df94d9ca..c5ef7236 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ jc changelog +2019xxxx v1.0.1 +- Fix env parser + 20191023 v0.9.1 - Add jobs parser - Add lsof parser diff --git a/jc/parsers/env.py b/jc/parsers/env.py index 2cebc027..c3164d5f 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -5,37 +5,23 @@ Usage: Example: $ env | jc --env -p -[ - { - "TERM": "xterm-256color" - }, - { - "SHELL": "/bin/bash" - }, - { - "USER": "root" - }, - { - "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" - }, - { - "PWD": "/bin" - }, - { - "LANG": "en_US.UTF-8" - }, - { - "HOME": "/root" - }, - { - "_": "/usr/bin/env" - } -] +{ + "TERM": "xterm-256color", + "SHELL": "/bin/bash", + "USER": "root", + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PWD": "/root", + "LANG": "en_US.UTF-8", + "HOME": "/root", + "LOGNAME": "root", + "_": "/usr/bin/env" +} + """ def parse(data): - output = [] + output = {} linedata = data.splitlines() @@ -45,9 +31,7 @@ def parse(data): if cleandata: for entry in cleandata: - output_line = {} parsed_line = entry.split('=', maxsplit=1) - output_line[parsed_line[0]] = parsed_line[1] - output.append(output_line) + output[parsed_line[0]] = parsed_line[1] return output