diff --git a/NEWS b/NEWS index 6ed814d..0e76bf0 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index b39668a..5ad1431 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -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), diff --git a/docs/how-to/set-up-backups.md b/docs/how-to/set-up-backups.md index b87b805..2d28837 100644 --- a/docs/how-to/set-up-backups.md +++ b/docs/how-to/set-up-backups.md @@ -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