Disable colored output when "--json" flag is used, so as to produce valid JSON ouput (#276).

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 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. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
1.4.21 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)) config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
configs, parse_logs = load_configurations(config_filenames, global_arguments.overrides) 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: try:
configure_logging( configure_logging(
verbosity_to_log_level(global_arguments.verbosity), verbosity_to_log_level(global_arguments.verbosity),

View file

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