summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2021-07-07 10:43:59 +1200
committerDouglas Bagnall <dbagnall@samba.org>2022-09-06 21:12:36 +0000
commiteefc030458674b5bb5b8338f7a3b9c1df48ad8ef (patch)
tree5e02828df0de2a0c821be12c85df50dcf0982613 /python
parentade31017583542aae13aabf819cb9f4fd7bea7b7 (diff)
downloadsamba-eefc030458674b5bb5b8338f7a3b9c1df48ad8ef.tar.gz
samba-eefc030458674b5bb5b8338f7a3b9c1df48ad8ef.tar.bz2
samba-eefc030458674b5bb5b8338f7a3b9c1df48ad8ef.zip
samba-tool: respect NO_COLOR env variable and --color options
This allows the NO_COLOR environment variable and --color=never to work for samba-tool commands that use this method. So far that means some parts of drs showrepl. 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>
Diffstat (limited to 'python')
-rw-r--r--python/samba/netcmd/__init__.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py
index bb70f72449e..eeb28964142 100644
--- a/python/samba/netcmd/__init__.py
+++ b/python/samba/netcmd/__init__.py
@@ -204,22 +204,11 @@ class Command(object):
"constants" in the colour module to be either real colours or empty
strings.
"""
- requested = requested.lower()
- if requested == 'no':
- colour.switch_colour_off()
-
- elif requested == 'yes':
- colour.switch_colour_on()
-
- elif requested == 'auto':
- if (hasattr(self.outf, 'isatty') and self.outf.isatty()):
- colour.switch_colour_on()
- else:
- colour.switch_colour_off()
-
- else:
- raise CommandError("Unknown --color option: %s "
- "please choose from yes, no, auto")
+ try:
+ colour.colour_if_wanted(self.outf, requested)
+ except ValueError as e:
+ raise CommandError(f"Unknown --color option: {requested} "
+ "please choose from always|never|auto")
class SuperCommand(Command):