Restrict colored_output value to always/never/auto.
This commit is contained in:
parent
7a570f8692
commit
23e66e08fa
5 changed files with 17 additions and 17 deletions
|
@ -128,10 +128,9 @@ def get_parsers():
|
||||||
|
|
||||||
parser['colored_output'] = argparse.ArgumentParser(add_help=False)
|
parser['colored_output'] = argparse.ArgumentParser(add_help=False)
|
||||||
parser['colored_output'].add_argument(
|
parser['colored_output'].add_argument(
|
||||||
'--colors',
|
'--colors', metavar='WHEN',
|
||||||
help='Use a colored output for different log levels.'
|
help="Colorize cdist's output based on log level; "
|
||||||
'It can be a boolean or "auto" (default) which enables this '
|
"WHEN is 'always', 'never', or 'auto'.",
|
||||||
'feature if stdout is a tty and disables it otherwise.',
|
|
||||||
action='store', dest='colored_output', required=False,
|
action='store', dest='colored_output', required=False,
|
||||||
choices=cdist.configuration.ColoredOutputOption.CHOICES)
|
choices=cdist.configuration.ColoredOutputOption.CHOICES)
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ class LogLevelOption(OptionBase):
|
||||||
|
|
||||||
|
|
||||||
class ColoredOutputOption(BooleanOption):
|
class ColoredOutputOption(BooleanOption):
|
||||||
CHOICES = tuple(configparser.ConfigParser.BOOLEAN_STATES) + ('auto',)
|
CHOICES = ('always', 'never', 'auto')
|
||||||
DEFAULT = 'auto'
|
DEFAULT = 'auto'
|
||||||
|
|
||||||
def get_converter(self):
|
def get_converter(self):
|
||||||
|
@ -258,8 +258,10 @@ class ColoredOutputOption(BooleanOption):
|
||||||
def translate(val):
|
def translate(val):
|
||||||
if isinstance(val, bool):
|
if isinstance(val, bool):
|
||||||
return val
|
return val
|
||||||
elif val in configparser.ConfigParser.BOOLEAN_STATES:
|
elif val == 'always':
|
||||||
return configparser.ConfigParser.BOOLEAN_STATES[val]
|
return True
|
||||||
|
elif val == 'never':
|
||||||
|
return False
|
||||||
elif val == 'auto':
|
elif val == 'auto':
|
||||||
return 'NO_COLOR' not in os.environ and sys.stdout.isatty()
|
return 'NO_COLOR' not in os.environ and sys.stdout.isatty()
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,9 @@
|
||||||
# colored_output
|
# colored_output
|
||||||
# Colorize cdist's output. If enabled, cdist will use different colors for
|
# Colorize cdist's output. If enabled, cdist will use different colors for
|
||||||
# different log levels.
|
# different log levels.
|
||||||
# Recognized values are 'yes'/'no', 'on'/'off', 'true'/'false', '1'/'0',
|
# Recognized values are 'always', 'never', and 'auto'.
|
||||||
# and 'auto'
|
# If the value is 'auto', colors are enabled if stdout is a TTY unless
|
||||||
# If the value is 'auto', colored output is enabled if stdout is a TTY
|
# the NO_COLOR (https://no-color.org/) environment variable is defined.
|
||||||
# unless the NO_COLOR (https://no-color.org/) environment variable is defined.
|
|
||||||
# colored_output = auto
|
# colored_output = auto
|
||||||
#
|
#
|
||||||
# conf_dir
|
# conf_dir
|
||||||
|
|
|
@ -369,9 +369,9 @@ CDIST_BETA
|
||||||
Enable beta functionalities.
|
Enable beta functionalities.
|
||||||
|
|
||||||
CDIST_COLORED_OUTPUT
|
CDIST_COLORED_OUTPUT
|
||||||
Use a colored output for different log levels.
|
Colorize cdist's output. If enabled, cdist will use different colors for
|
||||||
It can be a boolean or 'auto' (default) which enables this feature if
|
different log levels.
|
||||||
stdout is a tty and disables it otherwise.
|
Recognized values are 'always', 'never', and 'auto' (the default).
|
||||||
|
|
||||||
CDIST_CACHE_PATH_PATTERN
|
CDIST_CACHE_PATH_PATTERN
|
||||||
Custom cache path pattern.
|
Custom cache path pattern.
|
||||||
|
|
|
@ -111,11 +111,11 @@ All commands accept the following options:
|
||||||
**-h, --help**
|
**-h, --help**
|
||||||
Show the help screen.
|
Show the help screen.
|
||||||
|
|
||||||
**--colors COLORED_OUTPUT**
|
**--colors WHEN**
|
||||||
Colorize cdist's output. If enabled, cdist will use different colors for
|
Colorize cdist's output. If enabled, cdist will use different colors for
|
||||||
different log levels.
|
different log levels.
|
||||||
COLORED_OUTPUT recognizes the boolean values 'yes'/'no', 'on'/'off',
|
COLORED_OUTPUT recognizes the values 'always', 'never',
|
||||||
'true'/'false', '1'/'0', and 'auto' (the default).
|
and 'auto' (the default).
|
||||||
|
|
||||||
If the value is 'auto', colored output is enabled if stdout is a TTY
|
If the value is 'auto', colored output is enabled if stdout is a TTY
|
||||||
unless the NO_COLOR (https://no-color.org/) environment variable is defined.
|
unless the NO_COLOR (https://no-color.org/) environment variable is defined.
|
||||||
|
|
Loading…
Reference in a new issue