mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
samba-tool: make --color a general option
We don't put --color into options.SambaOptions because we can't handle the 'auto' case in the options module without knowing whether or not self.outf is a tty, and a) this might not be resolved and b) is fiddly to pass through. The .use_colour class flag allows samba-tool subcommands to avoid having --color, and is *also* useful in the short term for visualise and drs commands to avoid having this --color clobber their own bespoke versions (temporarily, during the transition). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Andrew Bartlett
parent
4c623356ce
commit
5dd4696fb7
@ -84,6 +84,7 @@ class Command(object):
|
||||
takes_optiongroups = {}
|
||||
|
||||
hidden = False
|
||||
use_colour = True
|
||||
|
||||
raw_argv = None
|
||||
raw_args = None
|
||||
@ -158,6 +159,12 @@ class Command(object):
|
||||
optiongroup = self.takes_optiongroups[name]
|
||||
optiongroups[name] = optiongroup(parser)
|
||||
parser.add_option_group(optiongroups[name])
|
||||
if self.use_colour:
|
||||
parser.add_option("--color",
|
||||
help="use colour if available (default: auto)",
|
||||
metavar="always|never|auto",
|
||||
default="auto")
|
||||
|
||||
return parser, optiongroups
|
||||
|
||||
def message(self, text):
|
||||
@ -180,6 +187,9 @@ class Command(object):
|
||||
del kwargs[option.dest]
|
||||
kwargs.update(optiongroups)
|
||||
|
||||
if self.use_colour:
|
||||
self.apply_colour_choice(kwargs.pop('color', 'auto'))
|
||||
|
||||
# Check for a min a max number of allowed arguments, whenever possible
|
||||
# The suffix "?" means zero or one occurence
|
||||
# The suffix "+" means at least one occurence
|
||||
|
@ -92,6 +92,7 @@ class cmd_drs_showrepl(Command):
|
||||
"""Show replication status."""
|
||||
|
||||
synopsis = "%prog [<DC>] [options]"
|
||||
use_colour = False
|
||||
|
||||
takes_optiongroups = {
|
||||
"sambaopts": options.SambaOptions,
|
||||
|
@ -92,6 +92,7 @@ class GraphCommand(Command):
|
||||
}
|
||||
takes_options = COMMON_OPTIONS + DOT_OPTIONS
|
||||
takes_args = ()
|
||||
use_colour = False
|
||||
|
||||
def get_db(self, H, sambaopts, credopts):
|
||||
lp = sambaopts.get_loadparm()
|
||||
|
Reference in New Issue
Block a user