From 23e66e08fab14f254c426c88271f461fe8499ba4 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sat, 6 Jun 2020 13:39:29 +0200 Subject: [PATCH] Restrict colored_output value to always/never/auto. --- cdist/argparse.py | 7 +++---- cdist/configuration.py | 8 +++++--- configuration/cdist.cfg.skeleton | 7 +++---- docs/src/cdist-reference.rst.sh | 6 +++--- docs/src/man1/cdist.rst | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cdist/argparse.py b/cdist/argparse.py index 0782654f..85dba246 100644 --- a/cdist/argparse.py +++ b/cdist/argparse.py @@ -128,10 +128,9 @@ def get_parsers(): parser['colored_output'] = argparse.ArgumentParser(add_help=False) parser['colored_output'].add_argument( - '--colors', - help='Use a colored output for different log levels.' - 'It can be a boolean or "auto" (default) which enables this ' - 'feature if stdout is a tty and disables it otherwise.', + '--colors', metavar='WHEN', + help="Colorize cdist's output based on log level; " + "WHEN is 'always', 'never', or 'auto'.", action='store', dest='colored_output', required=False, choices=cdist.configuration.ColoredOutputOption.CHOICES) diff --git a/cdist/configuration.py b/cdist/configuration.py index a12940b0..4ba43a7a 100644 --- a/cdist/configuration.py +++ b/cdist/configuration.py @@ -248,7 +248,7 @@ class LogLevelOption(OptionBase): class ColoredOutputOption(BooleanOption): - CHOICES = tuple(configparser.ConfigParser.BOOLEAN_STATES) + ('auto',) + CHOICES = ('always', 'never', 'auto') DEFAULT = 'auto' def get_converter(self): @@ -258,8 +258,10 @@ class ColoredOutputOption(BooleanOption): def translate(val): if isinstance(val, bool): return val - elif val in configparser.ConfigParser.BOOLEAN_STATES: - return configparser.ConfigParser.BOOLEAN_STATES[val] + elif val == 'always': + return True + elif val == 'never': + return False elif val == 'auto': return 'NO_COLOR' not in os.environ and sys.stdout.isatty() diff --git a/configuration/cdist.cfg.skeleton b/configuration/cdist.cfg.skeleton index 9c66b51b..14861592 100644 --- a/configuration/cdist.cfg.skeleton +++ b/configuration/cdist.cfg.skeleton @@ -16,10 +16,9 @@ # colored_output # Colorize cdist's output. If enabled, cdist will use different colors for # different log levels. -# Recognized values are 'yes'/'no', 'on'/'off', 'true'/'false', '1'/'0', -# and 'auto' -# 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. +# Recognized values are 'always', 'never', and 'auto'. +# If the value is 'auto', colors are enabled if stdout is a TTY unless +# the NO_COLOR (https://no-color.org/) environment variable is defined. # colored_output = auto # # conf_dir diff --git a/docs/src/cdist-reference.rst.sh b/docs/src/cdist-reference.rst.sh index a841862e..c0ac2c3e 100755 --- a/docs/src/cdist-reference.rst.sh +++ b/docs/src/cdist-reference.rst.sh @@ -369,9 +369,9 @@ CDIST_BETA Enable beta functionalities. CDIST_COLORED_OUTPUT - Use a colored output for different log levels. - It can be a boolean or 'auto' (default) which enables this feature if - stdout is a tty and disables it otherwise. + Colorize cdist's output. If enabled, cdist will use different colors for + different log levels. + Recognized values are 'always', 'never', and 'auto' (the default). CDIST_CACHE_PATH_PATTERN Custom cache path pattern. diff --git a/docs/src/man1/cdist.rst b/docs/src/man1/cdist.rst index 4def97b5..760ff8f6 100644 --- a/docs/src/man1/cdist.rst +++ b/docs/src/man1/cdist.rst @@ -111,11 +111,11 @@ All commands accept the following options: **-h, --help** Show the help screen. -**--colors COLORED_OUTPUT** +**--colors WHEN** Colorize cdist's output. If enabled, cdist will use different colors for different log levels. - COLORED_OUTPUT recognizes the boolean values 'yes'/'no', 'on'/'off', - 'true'/'false', '1'/'0', and 'auto' (the default). + COLORED_OUTPUT recognizes the values 'always', 'never', + and 'auto' (the default). 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.