Commit 94bb83a3 authored by Jiří Klimeš's avatar Jiří Klimeš

cli: allow specifying 'group.name' syntax for '--fields'

and use it for 'nmcli device show'.

This allows filtering output not only for whole groups, but also for individual
fields in commands that print data in groups (sections).

Example:
$ nmcli -f general.device,general.driver,ipv4,ipv6.address device show eth0
GENERAL.DEVICE:                         eth0
GENERAL.DRIVER:                         e1000e
IP4.ADDRESS[1]:                         ip = 10.0.5.228/23, gw = 10.0.5.254
IP4.ADDRESS[2]:                         ip = 5.5.5.5/32, gw = 5.5.5.1
IP4.DNS[1]:                             192.168.122.1
IP4.DNS[2]:                             8.8.8.8
IP4.DOMAIN[1]:                          mycompany.com
parent bec69e17
......@@ -30,7 +30,7 @@
#include "utils.h"
/* Available fields for IPv4 group */
static NmcOutputField nmc_fields_ip4_config[] = {
NmcOutputField nmc_fields_ip4_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 68}, /* 1 */
{"ROUTE", N_("ROUTE"), 68}, /* 2 */
......@@ -42,7 +42,7 @@ static NmcOutputField nmc_fields_ip4_config[] = {
#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN,WINS"
/* Available fields for DHCPv4 group */
static NmcOutputField nmc_fields_dhcp4_config[] = {
NmcOutputField nmc_fields_dhcp4_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"OPTION", N_("OPTION"), 80}, /* 1 */
{NULL, NULL, 0}
......@@ -50,7 +50,7 @@ static NmcOutputField nmc_fields_dhcp4_config[] = {
#define NMC_FIELDS_DHCP4_CONFIG_ALL "GROUP,OPTION"
/* Available fields for IPv6 group */
static NmcOutputField nmc_fields_ip6_config[] = {
NmcOutputField nmc_fields_ip6_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 95}, /* 1 */
{"ROUTE", N_("ROUTE"), 95}, /* 2 */
......@@ -61,7 +61,7 @@ static NmcOutputField nmc_fields_ip6_config[] = {
#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN"
/* Available fields for DHCPv6 group */
static NmcOutputField nmc_fields_dhcp6_config[] = {
NmcOutputField nmc_fields_dhcp6_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"OPTION", N_("OPTION"), 80}, /* 1 */
{NULL, NULL, 0}
......@@ -70,7 +70,10 @@ static NmcOutputField nmc_fields_dhcp6_config[] = {
gboolean
print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix)
print_ip4_config (NMIP4Config *cfg4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
{
GSList *list, *iter;
const GArray *array;
......@@ -89,7 +92,8 @@ print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix)
tmpl = nmc_fields_ip4_config;
tmpl_len = sizeof (nmc_fields_ip4_config);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_IP4_CONFIG_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -179,7 +183,10 @@ print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix)
}
gboolean
print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix)
print_ip6_config (NMIP6Config *cfg6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
{
GSList *list, *iter;
const GPtrArray *ptr_array;
......@@ -196,7 +203,8 @@ print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix)
tmpl = nmc_fields_ip6_config;
tmpl_len = sizeof (nmc_fields_ip6_config);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_IP6_CONFIG_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -274,7 +282,10 @@ print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix)
}
gboolean
print_dhcp4_config (NMDHCP4Config *dhcp4, NmCli *nmc, const char *group_prefix)
print_dhcp4_config (NMDHCP4Config *dhcp4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
{
GHashTable *table;
NmcOutputField *tmpl, *arr;
......@@ -292,7 +303,8 @@ print_dhcp4_config (NMDHCP4Config *dhcp4, NmCli *nmc, const char *group_prefix)
tmpl = nmc_fields_dhcp4_config;
tmpl_len = sizeof (nmc_fields_dhcp4_config);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DHCP4_CONFIG_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -318,7 +330,10 @@ print_dhcp4_config (NMDHCP4Config *dhcp4, NmCli *nmc, const char *group_prefix)
}
gboolean
print_dhcp6_config (NMDHCP6Config *dhcp6, NmCli *nmc, const char *group_prefix)
print_dhcp6_config (NMDHCP6Config *dhcp6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
{
GHashTable *table;
NmcOutputField *tmpl, *arr;
......@@ -336,7 +351,8 @@ print_dhcp6_config (NMDHCP6Config *dhcp6, NmCli *nmc, const char *group_prefix)
tmpl = nmc_fields_dhcp6_config;
tmpl_len = sizeof (nmc_fields_dhcp6_config);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DHCP6_CONFIG_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......
......@@ -32,10 +32,10 @@
#include "nmcli.h"
gboolean print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix);
gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix);
gboolean print_dhcp4_config (NMDHCP4Config *dhcp4, NmCli *nmc, const char *group_prefix);
gboolean print_dhcp6_config (NMDHCP6Config *dhcp6, NmCli *nmc, const char *group_prefix);
gboolean print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp4_config (NMDHCP4Config *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDHCP6Config *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field);
NMIP4Address *nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError **error);
NMIP6Address *nmc_parse_and_build_ip6_address (const char *ip_str, const char *gw_str, GError **error);
......
......@@ -351,13 +351,9 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
else
fields_str = nmc->required_fields;
print_settings_array = parse_output_fields (fields_str, nmc_fields_settings_names, &error);
print_settings_array = parse_output_fields (fields_str, nmc_fields_settings_names, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'list configured': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'list configured': %s; allowed fields: %s"),
error->message, NMC_FIELDS_SETTINGS_NAMES_ALL);
g_string_printf (nmc->return_text, _("Error: 'list configured': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return FALSE;
......@@ -367,7 +363,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
/* Main header */
nmc->print_fields.header_name = _("Connection details");
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL,
nmc_fields_settings_names, NULL);
nmc_fields_settings_names, FALSE, NULL, NULL);
nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
print_required_fields (nmc, nmc_fields_settings_names);
......@@ -499,7 +495,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
tmpl = nmc_fields_con_show;
tmpl_len = sizeof (nmc_fields_con_show);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error1);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error1);
if (error1)
goto error;
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error2))
......@@ -549,11 +545,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
error:
if (error1) {
if (error1->code == 0)
g_string_printf (nmc->return_text, _("Error: 'show configured': %s"), error1->message);
else
g_string_printf (nmc->return_text, _("Error: 'show configured': %s; allowed fields: %s"),
error1->message, NMC_FIELDS_CON_SHOW_ALL);
g_string_printf (nmc->return_text, _("Error: 'show configured': %s"), error1->message);
g_error_free (error1);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
......@@ -852,13 +844,9 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
else
fields_str = nmc->required_fields;
print_groups = parse_output_fields (fields_str, nmc_fields_con_active_details_groups, &error);
print_groups = parse_output_fields (fields_str, nmc_fields_con_active_details_groups, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'list active': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'list active': %s; allowed fields: %s"),
error->message, NMC_FIELDS_CON_ACTIVE_DETAILS_ALL);
g_string_printf (nmc->return_text, _("Error: 'list active': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return FALSE;
......@@ -868,7 +856,7 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
/* Main header */
nmc->print_fields.header_name = _("Active connection details");
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL,
nmc_fields_con_active_details_groups, NULL);
nmc_fields_con_active_details_groups, FALSE, NULL, NULL);
nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
print_required_fields (nmc, nmc_fields_con_active_details_groups);
......@@ -890,7 +878,7 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
/* Add field names */
tmpl = nmc_fields_con_show_active;
tmpl_len = sizeof (nmc_fields_con_show_active);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -916,10 +904,10 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
NMDHCP4Config *dhcp4 = nm_device_get_dhcp4_config (device);
NMDHCP6Config *dhcp6 = nm_device_get_dhcp6_config (device);
b1 = print_ip4_config (cfg4, nmc, "IP4");
b2 = print_dhcp4_config (dhcp4, nmc, "DHCP4");
b3 = print_ip6_config (cfg6, nmc, "IP6");
b4 = print_dhcp6_config (dhcp6, nmc, "DHCP6");
b1 = print_ip4_config (cfg4, nmc, "IP4", NULL);
b2 = print_dhcp4_config (dhcp4, nmc, "DHCP4", NULL);
b3 = print_ip6_config (cfg6, nmc, "IP6", NULL);
b4 = print_dhcp6_config (dhcp6, nmc, "DHCP6", NULL);
was_output = was_output || b1 || b2 || b3 || b4;
}
}
......@@ -943,7 +931,7 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
tmpl = nmc_fields_con_active_details_vpn;
tmpl_len = sizeof (nmc_fields_con_active_details_vpn);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -1025,7 +1013,7 @@ do_connections_show_active (NmCli *nmc, int argc, char **argv)
tmpl = nmc_fields_con_show_active + 1;
tmpl_len = sizeof (nmc_fields_con_show_active) - sizeof (NmcOutputField);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &err1);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err1);
if (err1)
goto error;
......@@ -1078,10 +1066,7 @@ do_connections_show_active (NmCli *nmc, int argc, char **argv)
error:
if (err1) {
if (err1->code == 0)
g_string_printf (nmc->return_text, _("Error: 'show active': %s"), err1->message);
else
g_string_printf (nmc->return_text, _("Error: 'show active': %s; allowed fields: %s"), err1->message, NMC_FIELDS_CON_ACTIVE_ALL);
g_string_printf (nmc->return_text, _("Error: 'show active': %s"), err1->message);
g_error_free (err1);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
......
......@@ -81,32 +81,6 @@ static NmcOutputField nmc_fields_dev_status[] = {
#define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE,CONNECTION"
/* Available sections for 'device show' */
static NmcOutputField nmc_fields_dev_show_sections[] = {
{"GENERAL", N_("GENERAL"), 0}, /* 0 */
{"CAPABILITIES", N_("CAPABILITIES"), 0}, /* 1 */
{"WIFI-PROPERTIES", N_("WIFI-PROPERTIES"), 0}, /* 2 */
{"AP", N_("AP"), 0}, /* 3 */
{"WIRED-PROPERTIES", N_("WIRED-PROPERTIES"), 0}, /* 4 */
{"WIMAX-PROPERTIES", N_("WIMAX-PROPERTIES"), 0}, /* 5 */
{"NSP", N_("NSP"), 0}, /* 6 */
{"IP4", N_("IP4"), 0}, /* 7 */
{"DHCP4", N_("DHCP4"), 0}, /* 8 */
{"IP6", N_("IP6"), 0}, /* 9 */
{"DHCP6", N_("DHCP6"), 0}, /* 10 */
{"BOND", N_("BOND"), 0}, /* 11 */
{"VLAN", N_("VLAN"), 0}, /* 12 */
{"CONNECTIONS", N_("CONNECTIONS"), 0}, /* 13 */
{NULL, NULL, 0}
};
#if WITH_WIMAX
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
#else
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
#endif
/* Available fields for 'device show' - GENERAL part */
static NmcOutputField nmc_fields_dev_show_general[] = {
{"NAME", N_("NAME"), 10}, /* 0 */
......@@ -161,7 +135,6 @@ static NmcOutputField nmc_fields_dev_show_wired_prop[] = {
#define NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL "NAME,CARRIER"
#define NMC_FIELDS_DEV_SHOW_WIRED_PROP_COMMON "NAME,CARRIER"
/* Available fields for 'device show' - wireless properties part */
static NmcOutputField nmc_fields_dev_show_wifi_prop[] = {
{"NAME", N_("NAME"), 18}, /* 0 */
......@@ -192,6 +165,7 @@ static NmcOutputField nmc_fields_dev_show_wimax_prop[] = {
#define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_COMMON "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID"
#endif
/* Available fields for 'device wifi list' */
static NmcOutputField nmc_fields_dev_wifi_list[] = {
{"NAME", N_("NAME"), 15}, /* 0 */
......@@ -253,6 +227,38 @@ static NmcOutputField nmc_fields_dev_show_vlan_prop[] = {
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,ID"
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,ID"
/* defined in common.c */
extern NmcOutputField nmc_fields_ip4_config[];
extern NmcOutputField nmc_fields_ip6_config[];
extern NmcOutputField nmc_fields_dhcp4_config[];
extern NmcOutputField nmc_fields_dhcp6_config[];
/* Available sections for 'device show' */
static NmcOutputField nmc_fields_dev_show_sections[] = {
{"GENERAL", N_("GENERAL"), 0, nmc_fields_dev_show_general + 1 }, /* 0 */
{"CAPABILITIES", N_("CAPABILITIES"), 0, nmc_fields_dev_show_cap + 1 }, /* 1 */
{"WIFI-PROPERTIES", N_("WIFI-PROPERTIES"), 0, nmc_fields_dev_show_wifi_prop + 1 }, /* 2 */
{"AP", N_("AP"), 0, nmc_fields_dev_wifi_list + 1 }, /* 3 */
{"WIRED-PROPERTIES", N_("WIRED-PROPERTIES"), 0, nmc_fields_dev_show_wired_prop + 1 }, /* 4 */
{"WIMAX-PROPERTIES", N_("WIMAX-PROPERTIES"), 0, nmc_fields_dev_show_wimax_prop + 1 }, /* 5 */
{"NSP", N_("NSP"), 0, nmc_fields_dev_wimax_list + 1 }, /* 6 */
{"IP4", N_("IP4"), 0, nmc_fields_ip4_config + 1 }, /* 7 */
{"DHCP4", N_("DHCP4"), 0, nmc_fields_dhcp4_config + 1 }, /* 8 */
{"IP6", N_("IP6"), 0, nmc_fields_ip6_config + 1 }, /* 9 */
{"DHCP6", N_("DHCP6"), 0, nmc_fields_dhcp6_config + 1 }, /* 10 */
{"BOND", N_("BOND"), 0, nmc_fields_dev_show_bond_prop + 1 }, /* 11 */
{"VLAN", N_("VLAN"), 0, nmc_fields_dev_show_vlan_prop + 1 }, /* 12 */
{"CONNECTIONS", N_("CONNECTIONS"), 0, nmc_fields_dev_show_connections + 1 }, /* 13 */
{NULL, NULL, 0, NULL }
};
#if WITH_WIMAX
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
#else
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
#endif
/* glib main loop variable - defined in nmcli.c */
extern GMainLoop *loop;
......@@ -590,6 +596,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
NMDHCP4Config *dhcp4;
NMDHCP6Config *dhcp6;
const char *base_hdr = _("Device details");
GPtrArray *fields_in_section = NULL;
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
fields_str = fields_common;
......@@ -598,13 +605,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
else
fields_str = nmc->required_fields;
sections_array = parse_output_fields (fields_str, nmc_fields_dev_show_sections, &error);
sections_array = parse_output_fields (fields_str, nmc_fields_dev_show_sections, TRUE, &fields_in_section, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'device show': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'device show': %s; allowed fields: %s"),
error->message, NMC_FIELDS_DEV_SHOW_SECTIONS_ALL);
g_string_printf (nmc->return_text, _("Error: 'device show': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return;
......@@ -613,7 +616,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* Main header */
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device));
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
nmc_fields_dev_show_general, NULL);
nmc_fields_dev_show_general, FALSE, NULL, NULL);
nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
print_required_fields (nmc, nmc_fields_dev_show_general);
......@@ -621,6 +624,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* Loop through the required sections and print them. */
for (k = 0; k < sections_array->len; k++) {
int section_idx = g_array_index (sections_array, int, k);
char *section_fld = (char *) g_ptr_array_index (fields_in_section, k);
if (nmc->print_output != NMC_PRINT_TERSE && !nmc->multiline_output && was_output)
printf ("\n"); /* Print empty line between groups in tabular mode */
......@@ -636,7 +640,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) {
tmpl = nmc_fields_dev_show_general;
tmpl_len = sizeof (nmc_fields_dev_show_general);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -689,7 +694,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[1].name)) {
tmpl = nmc_fields_dev_show_cap;
tmpl_len = sizeof (nmc_fields_dev_show_cap);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_CAP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -728,7 +734,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_show_wifi_prop;
tmpl_len = sizeof (nmc_fields_dev_show_wifi_prop);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -757,7 +764,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_wifi_list;
tmpl_len = sizeof (nmc_fields_dev_wifi_list);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -779,7 +787,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[4].name)) {
tmpl = nmc_fields_dev_show_wired_prop;
tmpl_len = sizeof (nmc_fields_dev_show_wired_prop);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -804,7 +813,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* Field names */
tmpl = nmc_fields_dev_show_wimax_prop;
tmpl_len = sizeof (nmc_fields_dev_show_wimax_prop);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -848,7 +858,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_wimax_list;
tmpl_len = sizeof (nmc_fields_dev_wimax_list);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_WIMAX_LIST_FOR_DEV_LIST, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIMAX_LIST_FOR_DEV_LIST,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -872,19 +883,19 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* IP4 */
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[7].name))
was_output = print_ip4_config (cfg4, nmc, nmc_fields_dev_show_sections[7].name);
was_output = print_ip4_config (cfg4, nmc, nmc_fields_dev_show_sections[7].name, section_fld);
/* DHCP4 */
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[8].name))
was_output = print_dhcp4_config (dhcp4, nmc, nmc_fields_dev_show_sections[8].name);
was_output = print_dhcp4_config (dhcp4, nmc, nmc_fields_dev_show_sections[8].name, section_fld);
/* IP6 */
if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[9].name))
was_output = print_ip6_config (cfg6, nmc, nmc_fields_dev_show_sections[9].name);
was_output = print_ip6_config (cfg6, nmc, nmc_fields_dev_show_sections[9].name, section_fld);
/* DHCP6 */
if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[10].name))
was_output = print_dhcp6_config (dhcp6, nmc, nmc_fields_dev_show_sections[10].name);
was_output = print_dhcp6_config (dhcp6, nmc, nmc_fields_dev_show_sections[10].name, section_fld);
/* Bond-specific information */
if ((NM_IS_DEVICE_BOND (device))) {
......@@ -909,7 +920,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_show_bond_prop;
tmpl_len = sizeof (nmc_fields_dev_show_bond_prop);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_BOND_PROP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BOND_PROP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -932,7 +944,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_show_vlan_prop;
tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -956,7 +969,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
tmpl = nmc_fields_dev_show_connections;
tmpl_len = sizeof (nmc_fields_dev_show_connections);
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, tmpl, NULL);
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->output_data, arr);
......@@ -999,6 +1013,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
if (sections_array)
g_array_free (sections_array, TRUE);
if (fields_in_section)
g_ptr_array_free (fields_in_section, TRUE);
}
static const char *
......@@ -1073,14 +1089,10 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
tmpl = nmc_fields_dev_status;
tmpl_len = sizeof (nmc_fields_dev_status);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'device status': %s; allowed fields: %s"),
error->message, NMC_FIELDS_DEV_STATUS_ALL);
g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
......@@ -1552,14 +1564,10 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
tmpl = nmc_fields_dev_wifi_list;
tmpl_len = sizeof (nmc_fields_dev_wifi_list);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s; allowed fields: %s"),
error->message, NMC_FIELDS_DEV_WIFI_LIST_ALL);
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
......@@ -2295,14 +2303,10 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv)
tmpl = nmc_fields_dev_wimax_list;
tmpl_len = sizeof (nmc_fields_dev_wimax_list);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'device wimax': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'device wimax': %s; allowed fields: %s"),
error->message, NMC_FIELDS_DEV_WIMAX_LIST_ALL);
g_string_printf (nmc->return_text, _("Error: 'device wimax': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
......
......@@ -205,13 +205,10 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
tmpl = nmc_fields_nm_status;
tmpl_len = sizeof (nmc_fields_nm_status);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: %s (allowed fields: %s)"), error->message, fields_all);
g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return FALSE;
......@@ -351,14 +348,10 @@ show_nm_permissions (NmCli *nmc)
tmpl = nmc_fields_nm_permissions;
tmpl_len = sizeof (nmc_fields_nm_permissions);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s; allowed fields: %s"),
error->message, NMC_FIELDS_NM_PERMISSIONS_ALL);
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return FALSE;
......@@ -410,14 +403,10 @@ show_general_logging (NmCli *nmc)
tmpl = nmc_fields_nm_logging;
tmpl_len = sizeof (nmc_fields_nm_logging);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) {
if (error->code == 0)
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
else
g_string_printf (nmc->return_text, _("Error: 'general logging': %s; allowed fields: %s"),
error->message, NMC_FIELDS_NM_LOGGING_ALL);
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return FALSE;
......
......@@ -74,14 +74,15 @@ typedef enum {
#define NMC_OF_FLAG_MAIN_HEADER_ADD 0x00000004 /* Print main header in addition to values/field names */
#define NMC_OF_FLAG_MAIN_HEADER_ONLY 0x00000008 /* Print main header only */
typedef struct {
const char *name; /* Field's name */
const char *name_l10n; /* Field's name for translation */
int width; /* Width in screen columns */
void *value; /* Value of current field - char* or char** (NULL-terminated array) */
gboolean value_is_array; /* Whether value is char ** instead of char* */
gboolean free_value; /* Whether to free the value */
guint32 flags; /* Flags - whether and how to print values/field names/headers */
typedef struct _NmcOutputField {
const char *name; /* Field's name */
const char *name_l10n; /* Field's name for translation */
int width; /* Width in screen columns */
struct _NmcOutputField *group; /* Points to an array with available section field names if this is a section (group) field */
void *value; /* Value of current field - char* or char** (NULL-terminated array) */
gboolean</