]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: with --json, error messages are in JSON
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 28 Feb 2024 03:14:24 +0000 (16:14 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 29 Feb 2024 01:31:31 +0000 (01:31 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/__init__.py

index ab99aedfb2d64f23e5270f5d58917bf31a3d5053..01497055d68588f84893674faf594ae0c327b399 100644 (file)
@@ -109,6 +109,19 @@ class Command(object):
         parser.print_usage()
 
     def _print_error(self, msg, evalue=None, klass=None):
+        if self.preferred_output_format == 'json':
+            if evalue is None:
+                evalue = 1
+            else:
+                msg = f"{msg} - {evalue}"
+            if klass is not None:
+                kwargs = {'error class': klass}
+            else:
+                kwargs = {}
+
+            self.print_json_status(evalue, msg, **kwargs)
+            return
+
         err = colour.c_DARK_RED("ERROR")
         klass = '' if klass is None else f'({klass})'