jpcli 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jpcli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A library to convert Linux command output to JSON
5
5
  Home-page: https://github.com/JaimeAdanCuevas/jpcli
6
6
  Author: Jaime Cuevas
@@ -23,12 +23,23 @@ def parse_command_output(command_output, parser_name):
23
23
  def main():
24
24
  parser = argparse.ArgumentParser(description='JP - JSON Parser for Linux commands')
25
25
  parser.add_argument('command', type=str, help='The Linux command to run')
26
- parser.add_argument('parser_name', type=str, nargs='?', default='', help='The name of the parser to use')
26
+ parser.add_argument('parser_name', type=str, nargs='?', default=None, help='The name of the parser to use')
27
27
 
28
28
  args = parser.parse_args()
29
29
  result = jpcli(args.command, args.parser_name)
30
30
  print(result)
31
31
 
32
- def jpcli(command, parser_name):
33
- output = run_command(command)
34
- return parse_command_output(output, parser_name)
32
+ def jpcli(command, parser_name=None):
33
+ result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
34
+ if result.returncode != 0:
35
+ print(f"Error: {result.stderr}", file=sys.stderr)
36
+ sys.exit(result.returncode)
37
+
38
+ command_output = result.stdout
39
+ if parser_name is None:
40
+ parser_name = command.split()[0] # Use the first word of the command as the parser name
41
+ return parse_command_output(command_output, parser_name)
42
+
43
+ if __name__ == '__main__':
44
+ main()
45
+
@@ -0,0 +1,24 @@
1
+ def parse(command_output):
2
+ lines = command_output.splitlines()
3
+ data = []
4
+ headers = []
5
+
6
+ # Extract headers from the first line
7
+ if lines:
8
+ headers = [header.strip() for header in lines[0].split() if header.strip()]
9
+ lines = lines[1:]
10
+
11
+ for line in lines:
12
+ if not line.strip(): # Skip empty lines
13
+ continue
14
+
15
+ values = [value.strip() for value in line.split() if value.strip()]
16
+ if len(values) != len(headers):
17
+ # For handling lines with different formats (like summary lines)
18
+ data.append({headers[0]: " ".join(values)})
19
+ else:
20
+ entry = {headers[i]: values[i] for i in range(len(headers))}
21
+ data.append(entry)
22
+
23
+ return data
24
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jpcli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A library to convert Linux command output to JSON
5
5
  Home-page: https://github.com/JaimeAdanCuevas/jpcli
6
6
  Author: Jaime Cuevas
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="jpcli",
8
- version="0.1.1",
8
+ version="0.1.3",
9
9
  author="Jaime Cuevas",
10
10
  author_email="adancuevas@outlook.com",
11
11
  description="A library to convert Linux command output to JSON",
@@ -1,11 +0,0 @@
1
- def parse(command_output):
2
- lines = command_output.strip().splitlines()
3
- headers = [header.strip() for header in lines[0].split()]
4
- data = []
5
-
6
- for line in lines[1:]:
7
- values = line.split()
8
- entry = {headers[i]: values[i] for i in range(len(values))}
9
- data.append(entry)
10
-
11
- return data
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes