aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli-modem-time.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2018-10-27 14:46:38 +0200
committerDan Williams <dcbw@redhat.com>2018-11-26 16:51:35 +0000
commitb0fba14b1e122522a1db2581779ffb94ee7cfa37 (patch)
treef0ab362f9e124b7f01f8c7e1b97a84d0c40f3edc /cli/mmcli-modem-time.c
parentcafc40245d2007ad3a9a33875fc6b71d25e6a254 (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-time.c')
-rw-r--r--cli/mmcli-modem-time.c36
1 files changed, 9 insertions, 27 deletions
diff --git a/cli/mmcli-modem-time.c b/cli/mmcli-modem-time.c
index 206ca599..b210e53d 100644
--- a/cli/mmcli-modem-time.c
+++ b/cli/mmcli-modem-time.c
@@ -33,6 +33,7 @@
#include "mmcli.h"
#include "mmcli-common.h"
+#include "mmcli-output.h"
/* Context */
typedef struct {
@@ -137,14 +138,11 @@ get_network_time_process_reply (gchar *time_string,
gchar *dst_offset = NULL;
gchar *leap_seconds = NULL;
- if (error)
+ if (error) {
g_printerr ("error: couldn't get current network time: '%s'\n",
error->message);
-
- /* 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 : "not available")
+ exit (EXIT_FAILURE);
+ }
if (timezone) {
if (mm_network_timezone_get_offset (timezone) != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
@@ -157,27 +155,11 @@ get_network_time_process_reply (gchar *time_string,
leap_seconds = g_strdup_printf ("%" G_GINT32_FORMAT, mm_network_timezone_get_leap_seconds (timezone));
}
- g_print ("\n"
- "%s\n"
- " ----------------------------\n"
- " Time | Current: '%s'\n"
- " ----------------------------\n"
- " Timezone | Offset: '%s'\n"
- " | DST offset: '%s'\n"
- " | Leap seconds: '%s'\n",
- mm_modem_time_get_path (ctx->modem_time),
- VALIDATE (time_string),
- VALIDATE (offset),
- VALIDATE (dst_offset),
- VALIDATE (leap_seconds));
-
- g_free (offset);
- g_free (dst_offset);
- g_free (leap_seconds);
- g_free (time_string);
-
- if (error)
- exit (EXIT_FAILURE);
+ mmcli_output_string_take (MMC_F_TIME_CURRENT, time_string);
+ mmcli_output_string_take (MMC_F_TIMEZONE_CURRENT, offset);
+ mmcli_output_string_take (MMC_F_TIMEZONE_DST_OFFSET, dst_offset);
+ mmcli_output_string_take (MMC_F_TIMEZONE_LEAP_SECONDS, leap_seconds);
+ mmcli_output_dump ();
}
static void