From 3ff6dc5ca3bcef3c4ac1645c0dc1a4516fe943cf Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Fri, 11 Oct 2019 10:50:39 -0700 Subject: [PATCH] json: Set json format at the end of parsing globals If we set and unset json format duging the time we are parsing globals we may end up with inconsistent outputs on errors. For exmaple: $ swupd diagnose -d -1 --json-output will have a different output then: $ swupd diagnose --json-output -d -1 Signed-off-by: Otavio Pontes --- src/globals.c | 4 +++- src/progress.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/globals.c b/src/globals.c index f8e9f0a1..1894bbfb 100644 --- a/src/globals.c +++ b/src/globals.c @@ -62,6 +62,7 @@ static int log_level = LOG_INFO; static bool quiet = false; static bool debug = false; static bool verbose = false; +static bool json_format = false; static void set_json_format(bool on) { @@ -595,7 +596,7 @@ static bool global_parse_opt(int opt, char *optarg) } return true; case 'j': - set_json_format(optarg_to_bool(optarg)); + json_format = optarg_to_bool(optarg); return true; case FLAG_NO_PROGRESS: progress_set_enabled(!optarg_to_bool(optarg)); @@ -767,6 +768,7 @@ int global_parse_options(int argc, char **argv, const struct global_options *opt log_level = LOG_INFO_VERBOSE; } log_set_level(log_level); + set_json_format(json_format); if (!config_found) { debug("No configuration file was found\n"); diff --git a/src/progress.c b/src/progress.c index 0d952747..0d3acc37 100644 --- a/src/progress.c +++ b/src/progress.c @@ -153,6 +153,7 @@ static void start_step() } else { progress_function(current_step_title, current_step, total_steps, 0); + last_percentage = 0; } }