Browse Source

cmd_ps: handle rpc response with own callbact for simplified output

Daniel-Constantin Mierla 8 years ago
parent
commit
525443cc9f
1 changed files with 16 additions and 3 deletions
  1. 16 3
      kamcli/commands/cmd_ps.py

+ 16 - 3
kamcli/commands/cmd_ps.py

@@ -1,6 +1,6 @@
-import os
-import time
+import sys
 import click
 import click
+import json
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
@@ -15,4 +15,17 @@ def cli(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'core.psx', [])
+    command_ctl(ctx, 'core.psx', [], {"func": cmd_ps_result_print})
+
+
+##
+#
+#
+def cmd_ps_result_print(ctx, response, params=None):
+    ctx.vlog("formatting the response for command ps")
+    rdata = json.loads(response)
+    if "result" in rdata:
+        for r in rdata["result"]:
+            ctx.printf("%4d %5d %s", r["IDX"], r["PID"], r["DSC"])
+    else:
+        print json.dumps(rdata, indent=4, separators=(',', ': '))