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.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.c')
-rw-r--r-- | cli/mmcli.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cli/mmcli.c b/cli/mmcli.c index 7349b215..80b9e656 100644 --- a/cli/mmcli.c +++ b/cli/mmcli.c @@ -34,6 +34,7 @@ #include "mmcli.h" #include "mmcli-common.h" +#include "mmcli-output.h" #define PROGRAM_NAME "mmcli" #define PROGRAM_VERSION PACKAGE_VERSION @@ -43,12 +44,17 @@ static GMainLoop *loop; static GCancellable *cancellable; /* Context */ +static gboolean output_keyvalue_flag; static gboolean verbose_flag; static gboolean version_flag; static gboolean async_flag; static gint timeout = 30; /* by default, use 30s for all operations */ static GOptionEntry main_entries[] = { + { "output-keyvalue", 'K', 0, G_OPTION_ARG_NONE, &output_keyvalue_flag, + "Run action with machine-friendly key-value output", + NULL + }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag, "Run action with verbose logs", NULL @@ -230,6 +236,16 @@ main (gint argc, gchar **argv) if (verbose_flag) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, log_handler, NULL); + /* Setup output */ + if (output_keyvalue_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 (MMC_OUTPUT_TYPE_HUMAN); + /* Setup signals */ signal (SIGINT, signals_handler); signal (SIGHUP, signals_handler); |