]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool visualise: expand set of --color switches
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 17 Aug 2022 01:15:15 +0000 (13:15 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 6 Sep 2022 21:12:36 +0000 (21:12 +0000)
To match convention, and elsewhere.

We can't easily use colour.is_colour_wanted() because we could (via
--output) be intending to write to a file that isn't open yet, so we
have no .isatty() to query.

Also, because --color-scheme implies --color (as documented in
--help), it trumps most 'auto' checks, but not NO_COLOR.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
python/samba/netcmd/visualize.py
selftest/knownfail.d/samba-tool-visualize [deleted file]

index 49e64794131b828097c16bb5bd166e142ec8cf90..ea8e696ee614e8106d672440897cbe1cc42f3ed2 100644 (file)
@@ -57,7 +57,8 @@ COMMON_OPTIONS = [
     Option("--utf8", help="Use utf-8 Unicode characters",
            action='store_true'),
     Option("--color", help="use color (yes, no, auto)",
-           choices=['yes', 'no', 'auto']),
+           choices=['yes', 'no', 'auto', 'always', 'never', 'force',
+                    'none', 'if-tty', 'tty']),
     Option("--color-scheme", help=("use this colour scheme "
                                    "(implies --color=yes)"),
            choices=list(COLOUR_SETS.keys())),
@@ -154,12 +155,15 @@ class GraphCommand(Command):
         """Heuristics to work out the colour scheme for distance matrices.
         Returning None means no colour, otherwise it sould be a colour
         from graph.COLOUR_SETS"""
-        if color == 'no':
+        if color in ('no', 'never', 'none'):
             return None
 
-        if color == 'auto':
+        if color in ('auto', 'tty', 'if-tty', None):
             if os.environ.get('NO_COLOR'):
                 return None
+            if color_scheme is not None:
+                # --color-scheme usually implies --color=yes.
+                return color_scheme
             if isinstance(output, str) and output != '-':
                 return None
             if not self.outf.isatty():
diff --git a/selftest/knownfail.d/samba-tool-visualize b/selftest/knownfail.d/samba-tool-visualize
deleted file mode 100644 (file)
index e92dd83..0000000
+++ /dev/null
@@ -1 +0,0 @@
-samba.tests.samba_tool.visualize.samba.tests.samba_tool.visualize.SambaToolVisualizeLdif.test_colour_auto_tty