Disable colored output when "--json" flag is used, so as to produce valid JSON ouput (#276).
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dan Helfman 2020-01-04 15:50:41 -08:00
parent c52f82f9ce
commit 5afe0e3d63
3 changed files with 12 additions and 5 deletions

1
NEWS
View File

@ -1,4 +1,5 @@
1.4.22.dev0
* #276: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput.
* In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
1.4.21

View File

@ -587,7 +587,13 @@ def main(): # pragma: no cover
config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
configs, parse_logs = load_configurations(config_filenames, global_arguments.overrides)
colorama.init(autoreset=True, strip=not should_do_markup(global_arguments.no_color, configs))
any_json_flags = any(
getattr(sub_arguments, 'json', False) for sub_arguments in arguments.values()
)
colorama.init(
autoreset=True,
strip=not should_do_markup(global_arguments.no_color or any_json_flags, configs),
)
try:
configure_logging(
verbosity_to_log_level(global_arguments.verbosity),

View File

@ -213,10 +213,10 @@ borgmatic to run.
## Colored output
Borgmatic produces colored terminal output by default. It is disabled when a
non-interactive terminal is detected (like a cron job). Otherwise, you can
disable it by passing the `--no-color` flag, setting the environment variable
`PY_COLORS=False`, or setting the `color` option to `false` in the `output`
section of configuration.
non-interactive terminal is detected (like a cron job), or when you use the
`--json` flag. Otherwise, you can disable it by passing the `--no-color` flag,
setting the environment variable `PY_COLORS=False`, or setting the `color`
option to `false` in the `output` section of configuration.
## Troubleshooting