nmcli/trivial: rename nmc_print() to nmc_print_table()

nmc_print() will be used for something else. Rename. Also,
nmc_print_table() is the better name anyway because the function does  a
lot of formatting and not simple printf().
This commit is contained in:
Thomas Haller 2023-02-06 17:00:00 +01:00
parent d3e2e9dc20
commit 4b2ded7a4a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
7 changed files with 137 additions and 135 deletions

View file

@ -354,15 +354,15 @@ print_ip_config(NMIPConfig *cfg,
g_strdup_printf("IP%c.%s", nm_utils_addr_family_to_char(addr_family), one_field);
}
if (!nmc_print(nmc_config,
(gpointer[]){cfg, NULL},
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP("IP4", metagen_ip4_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP("IP6", metagen_ip6_config, N_("GROUP")),
field_str,
&error)) {
if (!nmc_print_table(nmc_config,
(gpointer[]){cfg, NULL},
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP("IP4", metagen_ip4_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP("IP6", metagen_ip6_config, N_("GROUP")),
field_str,
&error)) {
return FALSE;
}
return TRUE;
@ -385,15 +385,15 @@ print_dhcp_config(NMDhcpConfig *dhcp,
g_strdup_printf("DHCP%c.%s", nm_utils_addr_family_to_char(addr_family), one_field);
}
if (!nmc_print(nmc_config,
(gpointer[]){dhcp, NULL},
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP("DHCP4", metagen_dhcp_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP("DHCP6", metagen_dhcp_config, N_("GROUP")),
field_str,
&error)) {
if (!nmc_print_table(nmc_config,
(gpointer[]){dhcp, NULL},
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP("DHCP4", metagen_dhcp_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP("DHCP6", metagen_dhcp_config, N_("GROUP")),
field_str,
&error)) {
return FALSE;
}
return TRUE;

View file

@ -1729,13 +1729,14 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc)
if (group_fld)
f = g_strdup_printf("GENERAL.%s", group_fld);
nmc_print(&nmc->nmc_config,
(gpointer[]){acon, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("GENERAL", metagen_con_active_general, N_("GROUP")),
f,
NULL);
nmc_print_table(
&nmc->nmc_config,
(gpointer[]){acon, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("GENERAL", metagen_con_active_general, N_("GROUP")),
f,
NULL);
was_output = TRUE;
continue;
}
@ -1786,13 +1787,13 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc)
if (nmc_fields_con_active_details_groups[group_idx]->nested == metagen_con_active_vpn) {
if (NM_IS_VPN_CONNECTION(acon)) {
nmc_print(&nmc->nmc_config,
(gpointer[]){acon, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("VPN", metagen_con_active_vpn, N_("NAME")),
group_fld,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){acon, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("VPN", metagen_con_active_vpn, N_("NAME")),
group_fld,
NULL);
was_output = TRUE;
}
continue;
@ -2367,14 +2368,14 @@ do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con
items = con_show_get_items(nmc, active_only, show_active_fields, order);
g_ptr_array_add(items, NULL);
if (!nmc_print(&nmc->nmc_config,
items->pdata,
NULL,
active_only ? _("NetworkManager active profiles")
: _("NetworkManager connection profiles"),
(const NMMetaAbstractInfo *const *) metagen_con_show,
fields_str,
&err))
if (!nmc_print_table(&nmc->nmc_config,
items->pdata,
NULL,
active_only ? _("NetworkManager active profiles")
: _("NetworkManager connection profiles"),
(const NMMetaAbstractInfo *const *) metagen_con_show,
fields_str,
&err))
goto finish;
} else {
gboolean new_line = FALSE;

View file

@ -1654,13 +1654,14 @@ show_device_info(NMDevice *device, NmCli *nmc)
if (nmc_fields_dev_show_sections[section_idx]->nested == metagen_device_detail_general) {
gs_free char *f = section_fld ? g_strdup_printf("GENERAL.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("GENERAL", metagen_device_detail_general, N_("NAME")),
f,
NULL);
nmc_print_table(
&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("GENERAL", metagen_device_detail_general, N_("NAME")),
f,
NULL);
was_output = TRUE;
continue;
}
@ -1669,15 +1670,15 @@ show_device_info(NMDevice *device, NmCli *nmc)
== metagen_device_detail_capabilities) {
gs_free char *f = section_fld ? g_strdup_printf("CAPABILITIES.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("CAPABILITIES",
metagen_device_detail_capabilities,
N_("NAME")),
f,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("CAPABILITIES",
metagen_device_detail_capabilities,
N_("NAME")),
f,
NULL);
was_output = TRUE;
continue;
}
@ -1687,15 +1688,15 @@ show_device_info(NMDevice *device, NmCli *nmc)
gs_free char *f =
section_fld ? g_strdup_printf("INTERFACE-FLAGS.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("INTERFACE-FLAGS",
metagen_device_detail_interface_flags,
N_("NAME")),
f,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("INTERFACE-FLAGS",
metagen_device_detail_interface_flags,
N_("NAME")),
f,
NULL);
was_output = TRUE;
continue;
}
@ -1706,15 +1707,15 @@ show_device_info(NMDevice *device, NmCli *nmc)
gs_free char *f =
section_fld ? g_strdup_printf("WIFI-PROPERTIES.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("WIFI-PROPERTIES",
metagen_device_detail_wifi_properties,
N_("NAME")),
f,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("WIFI-PROPERTIES",
metagen_device_detail_wifi_properties,
N_("NAME")),
f,
NULL);
was_output = TRUE;
}
continue;
@ -1770,15 +1771,15 @@ show_device_info(NMDevice *device, NmCli *nmc)
gs_free char *f =
section_fld ? g_strdup_printf("WIRED-PROPERTIES.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("WIRED-PROPERTIES",
metagen_device_detail_wired_properties,
N_("NAME")),
f,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("WIRED-PROPERTIES",
metagen_device_detail_wired_properties,
N_("NAME")),
f,
NULL);
was_output = TRUE;
}
continue;
@ -1899,15 +1900,15 @@ show_device_info(NMDevice *device, NmCli *nmc)
== metagen_device_detail_connections) {
gs_free char *f = section_fld ? g_strdup_printf("CONNECTIONS.%s", section_fld) : NULL;
nmc_print(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("CONNECTIONS",
metagen_device_detail_connections,
N_("NAME")),
f,
NULL);
nmc_print_table(&nmc->nmc_config,
(gpointer[]){device, NULL},
NULL,
NULL,
NMC_META_GENERIC_GROUP("CONNECTIONS",
metagen_device_detail_connections,
N_("NAME")),
f,
NULL);
was_output = TRUE;
continue;
}
@ -1976,13 +1977,13 @@ do_devices_status(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const
devices = nmc_get_devices_sorted(nmc->client);
if (!nmc_print(&nmc->nmc_config,
(gpointer *) devices,
NULL,
N_("Status of devices"),
(const NMMetaAbstractInfo *const *) metagen_device_status,
fields_str,
&error)) {
if (!nmc_print_table(&nmc->nmc_config,
(gpointer *) devices,
NULL,
N_("Status of devices"),
(const NMMetaAbstractInfo *const *) metagen_device_status,
fields_str,
&error)) {
g_string_printf(nmc->return_text, _("Error: 'device status': %s"), error->message);
g_error_free(error);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;

View file

@ -491,13 +491,13 @@ show_nm_status(NmCli *nmc, const char *pretty_header_name, const char *print_fld
else
fields_str = nmc->required_fields;
if (!nmc_print(&nmc->nmc_config,
(gpointer[]){nmc, NULL},
NULL,
pretty_header_name ?: N_("NetworkManager status"),
(const NMMetaAbstractInfo *const *) metagen_general_status,
fields_str,
&error)) {
if (!nmc_print_table(&nmc->nmc_config,
(gpointer[]){nmc, NULL},
NULL,
pretty_header_name ?: N_("NetworkManager status"),
(const NMMetaAbstractInfo *const *) metagen_general_status,
fields_str,
&error)) {
g_string_printf(nmc->return_text,
_("Error: only these fields are allowed: %s"),
fields_all);
@ -570,13 +570,13 @@ print_permissions(void *user_data)
nm_cli_spawn_pager(&nmc->nmc_config, &nmc->pager_data);
if (!nmc_print(&nmc->nmc_config,
permissions,
NULL,
_("NetworkManager permissions"),
(const NMMetaAbstractInfo *const *) metagen_general_permissions,
fields_str,
&error)) {
if (!nmc_print_table(&nmc->nmc_config,
permissions,
NULL,
_("NetworkManager permissions"),
(const NMMetaAbstractInfo *const *) metagen_general_permissions,
fields_str,
&error)) {
g_string_printf(nmc->return_text, _("Error: 'general permissions': %s"), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
@ -724,13 +724,13 @@ show_general_logging(NmCli *nmc)
} else
fields_str = nmc->required_fields;
if (!nmc_print(&nmc->nmc_config,
(gpointer const[]){&d, NULL},
NULL,
_("NetworkManager logging"),
(const NMMetaAbstractInfo *const *) metagen_general_logging,
fields_str,
&error)) {
if (!nmc_print_table(&nmc->nmc_config,
(gpointer const[]){&d, NULL},
NULL,
_("NetworkManager logging"),
(const NMMetaAbstractInfo *const *) metagen_general_logging,
fields_str,
&error)) {
g_string_printf(nmc->return_text, _("Error: 'general logging': %s"), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}

View file

@ -759,7 +759,7 @@ setting_details(const NmcConfig *nmc_config, NMSetting *setting, const char *one
fields_str = g_strdup_printf("%s.%s", nm_setting_get_name(setting), one_prop);
}
if (!nmc_print(
if (!nmc_print_table(
nmc_config,
(gpointer[]){setting, NULL},
NULL,

View file

@ -1387,13 +1387,13 @@ _print_do(const NmcConfig *nmc_config,
}
gboolean
nmc_print(const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const *fields,
const char *fields_str,
GError **error)
nmc_print_table(const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const *fields,
const char *fields_str,
GError **error)
{
gs_unref_ptrarray GPtrArray *gfree_keeper = NULL;
gs_free PrintDataCol *cols_data = NULL;

View file

@ -359,13 +359,13 @@ nmc_meta_generic_get_enum_with_detail(NmcMetaGenericGetEnumType get_enum_type,
/*****************************************************************************/
gboolean nmc_print(const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const *fields,
const char *fields_str,
GError **error);
gboolean nmc_print_table(const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const *fields,
const char *fields_str,
GError **error);
/*****************************************************************************/