Commit 59ea03cc authored by Thomas Haller's avatar Thomas Haller

cli: rework printing of vpn active-connection properties

use nmc_print() for the job.
parent 505a2113
This diff is collapsed.
......@@ -37,7 +37,7 @@ NMMetaColor nmc_active_connection_state_to_color (NMActiveConnectionState state)
extern const NmcMetaGenericInfo *const metagen_con_show[];
extern const NmcMetaGenericInfo *const metagen_con_active_general[];
extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[];
extern const NmcMetaGenericInfo *const metagen_con_active_vpn[];
extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[];
#endif /* NMC_CONNECTIONS_H */
......@@ -193,7 +193,7 @@ complete_fields (const char *option, const char *prefix)
complete_field (h, nmc_fields_ip6_config);
complete_field (h, metagen_con_show);
complete_field (h, metagen_con_active_general);
complete_field (h, nmc_fields_con_active_details_vpn);
complete_field (h, metagen_con_active_vpn);
complete_field (h, nmc_fields_con_active_details_groups);
complete_field (h, nmc_fields_dev_status);
complete_field (h, nmc_fields_dev_show_general);
......
......@@ -152,6 +152,14 @@ typedef enum {
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH,
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM,
NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE = 0,
NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME,
NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY,
NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER,
NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE,
NMC_GENERIC_INFO_TYPE_CON_VPN_CFG,
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM,
} NmcGenericInfoType;
#define NMC_HANDLE_COLOR(color) \
......@@ -220,8 +228,13 @@ nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type)
return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type);
}
typedef enum {
NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
NMC_META_GENERIC_GET_ENUM_TYPE_DASH,
} NmcMetaGenericGetEnumType;
static inline char *
nmc_meta_generic_get_enum_with_detail (gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type)
nmc_meta_generic_get_enum_with_detail (NmcMetaGenericGetEnumType get_enum_type, gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type)
{
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
......@@ -232,12 +245,23 @@ nmc_meta_generic_get_enum_with_detail (gint64 enum_val, const char *str_val, NMM
return g_strdup_printf ("%lld", (long long) enum_val);
}
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
* mode. That might not be desired, but it's done for certain properties to preserve
* previous behavior. */
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val));
return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val);
switch (get_enum_type) {
case NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES:
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
* mode. That might not be desired, but it's done for certain properties to preserve
* previous behavior. */
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val));
return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val);
case NMC_META_GENERIC_GET_ENUM_TYPE_DASH:
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
* mode. That might not be desired, but it's done for certain properties to preserve
* previous behavior. */
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return g_strdup_printf (_("%lld - %s"), (long long) enum_val, gettext (str_val));
return g_strdup_printf ("%lld - %s", (long long) enum_val, str_val);
}
g_return_val_if_reached (NULL);
}
/*****************************************************************************/
......
......@@ -2,7 +2,7 @@ location: clients/tests/test-client.py:939:test_004()/26
cmd: $NMCLI -t con s con-vpn-1
lang: pl_PL.UTF-8
returncode: 0
stdout: 2136 bytes
stdout: 2131 bytes
>>>
connection.id:con-vpn-1
connection.uuid:UUID-con-vpn-1-REPLACED-REPLACED-REP
......@@ -91,7 +91,7 @@ VPN.TYPE:openvpn
VPN.USERNAME:
VPN.GATEWAY:
VPN.BANNER:*** VPN connection con-vpn-1 ***
VPN.VPN-STATE:5 - Połączono z VPN
VPN.VPN-STATE:5 - VPN connected
VPN.CFG[1]:key1 = val1
VPN.CFG[2]:key2 = val2
VPN.CFG[3]:key3 = val3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment