2
0
Эх сурвалжийг харах

cmd_ps: handle rpc response with own callbact for simplified output

Daniel-Constantin Mierla 8 жил өмнө
parent
commit
525443cc9f

+ 16 - 3
kamcli/commands/cmd_ps.py

@@ -1,6 +1,6 @@
-import os
-import time
+import sys
 import click
+import json
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 
@@ -15,4 +15,17 @@ def cli(ctx):
 
     \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=(',', ': '))