From b0fba14b1e122522a1db2581779ffb94ee7cfa37 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 27 Oct 2018 14:46:38 +0200 Subject: cli: allow multiple output format types In addition to the standard human-friendly output, we now allow a machine-friendly key-value pair output, much easier to parse and use by programs that look at the mmcli output. This new key-value pair output should be treated as API from now on, so third-party programs can assume the output is compatible from one release to another. --- cli/mmcli-sim.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'cli/mmcli-sim.c') diff --git a/cli/mmcli-sim.c b/cli/mmcli-sim.c index c8713743..d31f07cb 100644 --- a/cli/mmcli-sim.c +++ b/cli/mmcli-sim.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Copyright (C) 2011 Aleksander Morgado + * Copyright (C) 2011-2018 Aleksander Morgado */ #include "config.h" @@ -33,6 +33,7 @@ #include "mmcli.h" #include "mmcli-common.h" +#include "mmcli-output.h" /* Context */ typedef struct { @@ -157,22 +158,12 @@ mmcli_sim_shutdown (void) static void print_sim_info (MMSim *sim) { - /* Not the best thing to do, as we may be doing _get() calls twice, but - * easiest to maintain */ -#undef VALIDATE -#define VALIDATE(str) (str ? str : "unknown") - - g_print ("SIM '%s'\n", - mm_sim_get_path (sim)); - g_print (" -------------------------\n" - " Properties | imsi : '%s'\n" - " | id : '%s'\n" - " | operator id : '%s'\n" - " | operator name : '%s'\n", - VALIDATE (mm_sim_get_imsi (sim)), - VALIDATE (mm_sim_get_identifier (sim)), - VALIDATE (mm_sim_get_operator_identifier (sim)), - VALIDATE (mm_sim_get_operator_name (sim))); + mmcli_output_string (MMC_F_SIM_GENERAL_DBUS_PATH, mm_sim_get_path (sim)); + mmcli_output_string (MMC_F_SIM_PROPERTIES_IMSI, mm_sim_get_imsi (sim)); + mmcli_output_string (MMC_F_SIM_PROPERTIES_ICCID, mm_sim_get_identifier (sim)); + mmcli_output_string (MMC_F_SIM_PROPERTIES_OPERATOR_ID, mm_sim_get_operator_identifier (sim)); + mmcli_output_string (MMC_F_SIM_PROPERTIES_OPERATOR_NAME, mm_sim_get_operator_name (sim)); + mmcli_output_dump (); } static void -- cgit v1.2.3-70-g09d2