]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: instances remember whether --json was requested
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 28 Feb 2024 03:13:15 +0000 (16:13 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 29 Feb 2024 01:31:31 +0000 (01:31 +0000)
All our subcommands are going to learn --json eventually, and they
shouldn't all have to do this individually.

The next commit uses this to automatically format CommandErrors as JSON.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/__init__.py

index 637b393ab82633843b428b7d2f0abb797052c286..ab99aedfb2d64f23e5270f5d58917bf31a3d5053 100644 (file)
@@ -93,6 +93,7 @@ class Command(object):
     raw_argv = None
     raw_args = None
     raw_kwargs = None
+    preferred_output_format = None
 
     def _set_files(self, outf=None, errf=None):
         if outf is not None:
@@ -300,6 +301,13 @@ class Command(object):
                     del kwargs[option.dest]
         kwargs.update(optiongroups)
 
+        if kwargs.get('output_format') == 'json':
+            self.preferred_output_format = 'json'
+        else:
+            # we need to reset this for the tests that reuse the
+            # samba-tool object.
+            self.preferred_output_format = None
+
         if self.use_colour:
             self.apply_colour_choice(kwargs.pop('color', 'auto'))