Przeglądaj źródła

ioutils: handle context output format

Daniel-Constantin Mierla 5 lat temu
rodzic
commit
8061ba3d66
1 zmienionych plików z 11 dodań i 8 usunięć
  1. 11 8
      kamcli/ioutils.py

+ 11 - 8
kamcli/ioutils.py

@@ -17,15 +17,18 @@ ioutils_formats_list = ["raw", "json", "table", "dict"]
 def ioutils_dbres_print(ctx, oformat, ostyle, res):
     """ print a database result using different formats and styles """
     if oformat is None:
-        if ioutils_tabulate_format is True:
-            oformat = "table"
+        if ctx.oformat is None:
+            if ioutils_tabulate_format is True:
+                oformat = "table"
+            else:
+                oformat = "json"
         else:
-            oformat = "json"
-    else:
-        if oformat == "table":
-            if ioutils_tabulate_format is False:
-                ctx.log("Package tabulate is not installed")
-                sys.exit()
+            oformat = ctx.oformat
+
+    if oformat == "table":
+        if ioutils_tabulate_format is False:
+            ctx.log("Package tabulate is not installed")
+            sys.exit()
 
     if ostyle is None:
         ostyle = "grid"