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-modem-voice.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-modem-voice.c')
-rw-r--r-- | cli/mmcli-modem-voice.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/cli/mmcli-modem-voice.c b/cli/mmcli-modem-voice.c index e5bb81d2..089523ef 100644 --- a/cli/mmcli-modem-voice.c +++ b/cli/mmcli-modem-voice.c @@ -34,6 +34,7 @@ #include "mmcli.h" #include "mmcli-common.h" +#include "mmcli-output.h" /* Context */ typedef struct { @@ -160,39 +161,35 @@ build_call_properties_from_input (const gchar *properties_string) } static void -print_call_short_info (MMCall *call) +output_call_info (MMCall *call) { - g_print ("\t%s %s (%s)\n", - mm_call_get_path (call), - mm_call_direction_get_string (mm_call_get_direction (call)), - mm_call_state_get_string (mm_call_get_state (call))); + gchar *extra; + + extra = g_strdup_printf ("%s (%s)", + mm_call_direction_get_string (mm_call_get_direction (call)), + mm_call_state_get_string (mm_call_get_state (call))); + mmcli_output_listitem (MMC_F_CALL_LIST_DBUS_PATH, + " ", + mm_call_get_path (call), + extra); + g_free (extra); } static void list_process_reply (GList *result, const GError *error) { + GList *l; + if (error) { g_printerr ("error: couldn't list call: '%s'\n", error->message); exit (EXIT_FAILURE); } - g_print ("\n"); - if (!result) { - g_print ("No calls were found\n"); - } else { - GList *l; - - g_print ("Found %u calls:\n", g_list_length (result)); - for (l = result; l; l = g_list_next (l)) { - MMCall *call = MM_CALL (l->data); - - print_call_short_info (call); - g_object_unref (call); - } - g_list_free (result); - } + for (l = result; l; l = g_list_next (l)) + output_call_info (MM_CALL (l->data)); + mmcli_output_list_dump (MMC_F_CALL_LIST_DBUS_PATH); } static void @@ -219,8 +216,7 @@ create_process_reply (MMCall *call, exit (EXIT_FAILURE); } - g_print ("Successfully created new call:\n"); - print_call_short_info (call); + g_print ("Successfully created new call: %s\n", mm_call_get_path (call)); g_object_unref (call); } |