aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli.c
diff options
context:
space:
mode:
authorMaxim Anisimov <maxim.anisimov.ua@gmail.com>2019-08-08 11:12:33 +0300
committerAleksander Morgado <aleksander@aleksander.es>2019-08-28 18:17:55 +0200
commitd1ac5ca16bfbc2475eb379b48e981e035f908b50 (patch)
treef94a5b4fb4fa6bcf88834c41ced191a6f9a994c9 /cli/mmcli.c
parentb0ec3030a3e5519d75c2268fa20062edd2dacf4e (diff)
mmcli: add json output support
Signed-off-by: Maxim Anisimov <maxim.anisimov.ua@gmail.com>
Diffstat (limited to 'cli/mmcli.c')
-rw-r--r--cli/mmcli.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/cli/mmcli.c b/cli/mmcli.c
index 6953672d..ab08f33d 100644
--- a/cli/mmcli.c
+++ b/cli/mmcli.c
@@ -45,6 +45,7 @@ static GCancellable *cancellable;
/* Context */
static gboolean output_keyvalue_flag;
+static gboolean output_json_flag;
static gboolean verbose_flag;
static gboolean version_flag;
static gboolean async_flag;
@@ -55,6 +56,10 @@ static GOptionEntry main_entries[] = {
"Run action with machine-friendly key-value output",
NULL
},
+ { "output-json", 'J', 0, G_OPTION_ARG_NONE, &output_json_flag,
+ "Run action with machine-friendly json output",
+ NULL
+ },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag,
"Run action with verbose logs",
NULL
@@ -237,14 +242,19 @@ main (gint argc, gchar **argv)
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, log_handler, NULL);
/* Setup output */
- if (output_keyvalue_flag) {
+ if (output_keyvalue_flag && output_json_flag) {
+ g_printerr ("error: only one output type supported at the same time\n");
+ exit (EXIT_FAILURE);
+ }
+ if (output_keyvalue_flag || output_json_flag) {
if (verbose_flag) {
g_printerr ("error: cannot set verbose output in keyvalue output type\n");
exit (EXIT_FAILURE);
}
- mmcli_output_set (MMC_OUTPUT_TYPE_KEYVALUE);
- } else
+ mmcli_output_set (output_keyvalue_flag ? MMC_OUTPUT_TYPE_KEYVALUE : MMC_OUTPUT_TYPE_JSON);
+ } else {
mmcli_output_set (MMC_OUTPUT_TYPE_HUMAN);
+ }
/* Setup signals */
signal (SIGINT, signals_handler);