diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2018-02-27 16:28:28 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2018-02-28 09:32:28 +0100 |
commit | bfebf9d9598186d57eb58b1d7431b90073f10203 (patch) | |
tree | 80655f2114867ebe2ec652bd4eff4132291f7782 | |
parent | d5c4356f61941eff7c795ec44f8eed4e4fd3dc23 (diff) | |
download | NetworkManager-bfebf9d9598186d57eb58b1d7431b90073f10203.tar.gz |
nmcli: add overview mode to skip default values in outputbg/nmcli-overview
(final name of the option still to be defined)
Example:
$ nmcli -o connection show wifi-home
connection.id: wifi-home
connection.uuid: 8308c425-f2a7-4021-9afc-37bde7253c6d
connection.type: 802-11-wireless
connection.timestamp: 1519264421
connection.permissions: user:bgalvani
802-11-wireless.ssid: home
802-11-wireless.mode: infrastructure
802-11-wireless-security.key-mgmt: wpa-psk
802-11-wireless-security.auth-alg: open
ipv4.method: auto
ipv6.method: auto
https://bugzilla.redhat.com/show_bug.cgi?id=1434527
-rw-r--r-- | clients/cli/nmcli.c | 16 | ||||
-rw-r--r-- | clients/cli/nmcli.h | 1 | ||||
-rw-r--r-- | clients/cli/utils.c | 10 |
3 files changed, 22 insertions, 5 deletions
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index 76dda05096..ec23ff431b 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -184,6 +184,7 @@ usage (void) g_printerr (_("Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }\n" "\n" "OPTIONS\n" + " -o[verview] overview mode (hide default values)\n" " -t[erse] terse output\n" " -p[retty] pretty output\n" " -m[ode] tabular|multiline output mode\n" @@ -295,9 +296,10 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; if (argc == 1 && nmc->complete) { - nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--colors", "--escape", - "--fields", "--nocheck", "--get-values", - "--wait", "--version", "--help", NULL); + nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--overview", + "--colors", "--escape", + "--fields", "--nocheck", "--get-values", + "--wait", "--version", "--help", NULL); } if (argv[0][1] == '-' && argv[0][2] == '\0') { @@ -306,7 +308,9 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; } - if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) { + if (matches_arg (nmc, &argc, &argv, "-overview", NULL)) { + nmc->nmc_config_mutable.overview = TRUE; + } else if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) { if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) { g_string_printf (nmc->return_text, _("Error: Option '--terse' is specified the second time.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -415,6 +419,10 @@ process_command_line (NmCli *nmc, int argc, char **argv) next_arg (nmc, &argc, &argv, NULL); } + /* Ignore --overview when fields are set explicitly */ + if (nmc->required_fields) + nmc->nmc_config_mutable.overview = FALSE; + /* Now run the requested command */ nmc_do_cmd (nmc, nmcli_cmds, *argv, argc, argv); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index cccad8462a..cbde4359f9 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -116,6 +116,7 @@ typedef struct _NmcConfig { bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */ bool in_editor; /* Whether running the editor - nmcli con edit' */ bool show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */ + bool overview; /* Overview mode (hide default values) */ } NmcConfig; typedef struct _NmcOutputData { diff --git a/clients/cli/utils.c b/clients/cli/utils.c index abf81fc521..6a2e899752 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -1004,6 +1004,7 @@ typedef struct { const PrintDataCol *col; const char *title; bool title_to_free:1; + bool skip:1; int width; } PrintDataHeaderCell; @@ -1102,6 +1103,7 @@ _print_fill (const NmcConfig *nmc_config, header_cell->col_idx = col_idx; header_cell->col = col; + header_cell->skip = FALSE; header_cell->title = nm_meta_abstract_info_get_name (info, TRUE); if ( nmc_config->multiline_output @@ -1136,7 +1138,7 @@ _print_fill (const NmcConfig *nmc_config, for (i_col = 0; i_col < header_row->len; i_col++) { char *to_free = NULL; PrintDataCell *cell = &cells_line[i_col]; - const PrintDataHeaderCell *header_cell; + PrintDataHeaderCell *header_cell; const NMMetaAbstractInfo *info; NMMetaAccessorGetOutFlags text_out_flags, color_out_flags; gconstpointer value; @@ -1157,6 +1159,9 @@ _print_fill (const NmcConfig *nmc_config, &text_out_flags, &is_default, (gpointer *) &to_free); + + header_cell->skip = nmc_config->overview && is_default; + if (NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_STRV)) { if (value) { if (nmc_config->multiline_output) { @@ -1240,6 +1245,9 @@ _print_skip_column (const NmcConfig *nmc_config, selection_item = header_cell->col->selection_item; info = selection_item->info; + if (header_cell->skip) + return TRUE; + if (nmc_config->multiline_output) { if (info->meta_type == &nm_meta_type_setting_info_editor) { /* we skip the "name" entry for the setting in multiline output. */ |