From fd371119869a58fff5835e6d975e6209999ae599 Mon Sep 17 00:00:00 2001 From: Antonio Cardace Date: Wed, 15 Apr 2020 10:10:58 +0200 Subject: [PATCH 1/4] clients: allow properties to be hidden if they have the default value (cherry picked from commit b94fcb2a9408134a1e0c26cecb196de2c3f21873) --- clients/common/nm-meta-setting-desc.c | 30 +++++++++++++++++++-------- clients/common/nm-meta-setting-desc.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 03f9b313ce..efad09ec57 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -8156,6 +8156,8 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info, gpointer *out_to_free) { const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; + gboolean is_default_local = FALSE; + gconstpointer r; nm_assert (!out_to_free || !*out_to_free); nm_assert (out_flags && !*out_flags); @@ -8173,15 +8175,25 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info, return _get_text_hidden (get_type); } - return info->property_type->get_fcn (info, - environment, - environment_user_data, - target, - get_type, - get_flags, - out_flags, - out_is_default, - out_to_free); + if ( info->hide_if_default + && !out_is_default) + out_is_default = &is_default_local; + + r = info->property_type->get_fcn (info, + environment, + environment_user_data, + target, + get_type, + get_flags, + out_flags, + out_is_default, + out_to_free); + + if ( info->hide_if_default + && *out_is_default) + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE; + + return r; } diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index c728a1502c..2ba48f5de2 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -376,6 +376,7 @@ struct _NMMetaPropertyInfo { bool is_secret:1; bool is_cli_option:1; + bool hide_if_default:1; const char *prompt; From fc582312f724597ceabb69373eaf4b2bc2c181a1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Apr 2020 10:34:03 +0200 Subject: [PATCH 2/4] cli: let _print_fill() hide option if NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE is set Regardless, whether the option is also currently the default. (cherry picked from commit 69eca2539132557fe875e12361eaadaf15533fa7) --- clients/cli/utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/cli/utils.c b/clients/cli/utils.c index d0d553b9f2..5e54fdb1a6 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -1078,9 +1078,9 @@ _print_fill (const NmcConfig *nmc_config, nm_assert (!to_free || value == to_free); - if ( is_default - && ( nmc_config->overview - || NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE))) { + if ( ( is_default + && nmc_config->overview) + || NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE)) { /* don't mark the entry for display. This is to shorten the output in case * the property is the default value. But we only do that, if the user * opts in to this behavior (-overview), or of the property marks itself From 486161cff425b98e9256ea9ff5410689397fd94e Mon Sep 17 00:00:00 2001 From: Antonio Cardace Date: Wed, 15 Apr 2020 10:13:19 +0200 Subject: [PATCH 3/4] bridge: make some advanced options hidden if default The options are: * group-address * multicast-querier * multicast-query-use-ifaddr * multicast-router * vlan-stats-enabled * vlan-protocol (cherry picked from commit 3af07fd4157c02690b96d99fa8d2b27392e27b2e) --- clients/common/nm-meta-setting-desc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index efad09ec57..c2f6b71769 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -4892,6 +4892,7 @@ static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_ADDRESS, .property_type = &_pt_gobject_mac, + .hide_if_default = TRUE, ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, .is_cli_option = TRUE, @@ -4901,9 +4902,11 @@ static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERIER, .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_SNOOPING, .is_cli_option = TRUE, @@ -4913,6 +4916,7 @@ static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_ROUTER, .property_type = &_pt_gobject_string, + .hide_if_default = TRUE, .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( .values_static = NM_MAKE_STRV ("auto", "disabled", @@ -4927,9 +4931,11 @@ static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_PROTOCOL, .property_type = &_pt_gobject_string, + .hide_if_default = TRUE, .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( .values_static = NM_MAKE_STRV ("802.1Q", "802.1ad"), From aacf8bd27da4e8778959eb650a58193eb202936d Mon Sep 17 00:00:00 2001 From: Antonio Cardace Date: Wed, 15 Apr 2020 10:15:52 +0200 Subject: [PATCH 4/4] ethtool: refactor how options are hidden if default Just use the new flag NMMetaPropertyInfo. (cherry picked from commit a5916de5990f9ddd1e366fb74ba96702734f56b6) --- clients/common/nm-meta-setting-desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index c2f6b71769..c821c21342 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -4102,7 +4102,6 @@ _get_fcn_ethtool (ARGS_GET_FCN) else { s = NULL; NM_SET_OUT (out_is_default, TRUE); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE; } if (s && get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) @@ -5320,6 +5319,7 @@ static const NMMetaPropertyInfo *const property_infos_DCB[] = { #define PROPERTY_INFO_ETHTOOL(xname) \ PROPERTY_INFO (NM_ETHTOOL_OPTNAME_##xname, NULL, \ .property_type = &_pt_ethtool, \ + .hide_if_default = TRUE, \ .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (ethtool, \ .ethtool_id = NM_ETHTOOL_ID_##xname, \ ), \