summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Giudici <fgiudici@redhat.com>2017-01-17 14:20:56 +0100
committerFrancesco Giudici <fgiudici@redhat.com>2017-03-24 13:04:23 +0100
commitc155f3351a38e1f23d31db55d5221fe401bfb942 (patch)
tree0c21992b302ef2c0e7ba555c78df04f7ca99279a
parentb915fe5d67ef1f26bc24576d3cb861f5bb8d40eb (diff)
downloadNetworkManager-fg/nmcli_parsing_part_II_rh1391170.tar.gz
nmcli: add -g[et-vars] as -t -f <arg> shortcutfg/nmcli_parsing_part_II_rh1391170
-rw-r--r--clients/cli/nmcli.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index 1049b31da5..4e6f16de2f 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -176,6 +176,7 @@ usage (void)
" -m[ode] tabular|multiline output mode\n"
" -c[olors] auto|yes|no whether to use colors in output\n"
" -f[ields] <field1,field2,...>|all|common specify fields to output\n"
+ " -g[et-vars] <field1,field2,...>|all|common shortcut for -m tabular -t -f <args>\n"
" -e[scape] yes|no escape columns separators in values\n"
" -a[sk] ask for missing parameters\n"
" -s[how-secrets] allow displaying passwords\n"
@@ -231,7 +232,7 @@ process_command_line (NmCli *nmc, int argc, char **argv)
if (argc == 1 && nmc->complete) {
nmc_complete_strings (opt, "--terse", "--pretty", "--mode", "--colors", "--escape",
"--fields", "--nocheck", "--ask", "--show-secrets",
- "--wait", "--version", "--help", NULL);
+ "--get-vars", "--wait", "--version", "--help", NULL);
}
if (opt[1] == '-') {
@@ -332,6 +333,21 @@ process_command_line (NmCli *nmc, int argc, char **argv)
if (argc == 1 && nmc->complete)
complete_fields (argv[0]);
nmc->required_fields = g_strdup (argv[0]);
+ } else if (matches (opt, "-get-vars")) {
+ if (next_arg (&argc, &argv) != 0) {
+ g_string_printf (nmc->return_text, _("Error: fields for '%s' options are missing."), opt);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ return FALSE;
+ }
+ if (argc == 1 && nmc->complete)
+ complete_fields (argv[0]);
+ nmc->required_fields = g_strdup (argv[0]);
+ nmc->print_output = NMC_PRINT_TERSE;
+ /* We want fixed tabular mode here, but just set the mode specified and rely on the initialization
+ * in nmc_init: in this way we allow use of "-m multiline" to swap the output mode also if placed
+ * before the "-g <field>" flag (-g may be still more practical and easy to remember than -t -f).
+ */
+ nmc->mode_specified = TRUE;
} else if (matches (opt, "-nocheck")) {
/* ignore for backward compatibility */
} else if (matches (opt, "-ask")) {