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 <otavio.pontes@intel.com>
This commit is contained in:
Otavio Pontes
2019-10-18 09:27:25 -07:00
parent 66ea5fea0f
commit 3ff6dc5ca3
2 changed files with 4 additions and 1 deletions
+3 -1
View File
@@ -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");
+1
View File
@@ -153,6 +153,7 @@ static void start_step()
} else {
progress_function(current_step_title, current_step, total_steps,
0);
last_percentage = 0;
}
}