diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-10-27 14:46:38 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-11-26 16:51:35 +0000 |
commit | b0fba14b1e122522a1db2581779ffb94ee7cfa37 (patch) | |
tree | f0ab362f9e124b7f01f8c7e1b97a84d0c40f3edc /cli/mmcli-sim.c | |
parent | cafc40245d2007ad3a9a33875fc6b71d25e6a254 (diff) |
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.
Diffstat (limited to 'cli/mmcli-sim.c')
-rw-r--r-- | cli/mmcli-sim.c | 25 |
1 files changed, 8 insertions, 17 deletions
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 <http://www.gnu.org/licenses/>. * - * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + * Copyright (C) 2011-2018 Aleksander Morgado <aleksander@aleksander.es> */ #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 |