From 37f92c6cc69b220439aef0c687c92a8e6baeb211 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 17 Aug 2022 13:15:15 +1200 Subject: [PATCH] samba-tool visualise: expand set of --color switches 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 Reviewed-by: Andrew Bartlett Reviewed-by: Joseph Sutton --- python/samba/netcmd/visualize.py | 10 +++++++--- selftest/knownfail.d/samba-tool-visualize | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) delete mode 100644 selftest/knownfail.d/samba-tool-visualize diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 49e64794131..ea8e696ee61 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -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 index e92dd83a8fb..00000000000 --- a/selftest/knownfail.d/samba-tool-visualize +++ /dev/null @@ -1 +0,0 @@ -samba.tests.samba_tool.visualize.samba.tests.samba_tool.visualize.SambaToolVisualizeLdif.test_colour_auto_tty -- 2.47.3