summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-04-27 09:48:16 +0200
committerThomas Haller <thaller@redhat.com>2021-05-03 10:11:22 +0200
commit3f0812e5046e1f4b6f4b45386b4aa7f0073a1117 (patch)
tree3b17c9e1c75a0f004bde7e6965c5f8763a2a3c5d
parent7df7d46bfed9b8689297bec4721f1a7c5d5f1ff5 (diff)
downloadNetworkManager-3f0812e5046e1f4b6f4b45386b4aa7f0073a1117.tar.gz
cli: add _pt_gobject_ternary property type
This will be used for NMTernary properties. The get() method is still the same as for _pt_gobject_enum, but the setter and complete functions are more flexible to also allow yes/true and any unique abbreviations.
-rw-r--r--src/libnmc-setting/nm-meta-setting-desc.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c
index 7238ef17ce..8c4528c2e0 100644
--- a/src/libnmc-setting/nm-meta-setting-desc.c
+++ b/src/libnmc-setting/nm-meta-setting-desc.c
@@ -1282,6 +1282,23 @@ static gboolean _set_fcn_gobject_bool(ARGS_SET_FCN)
return _set_fcn_gobject_bool_impl(property_info, setting, modifier, value, error);
}
+static gboolean _set_fcn_gobject_ternary(ARGS_SET_FCN)
+{
+ NMTernary val;
+
+ nm_assert(_gobject_property_get_gtype(G_OBJECT(setting), property_info->property_name)
+ == NM_TYPE_TERNARY);
+
+ if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value))
+ return _gobject_property_reset_default(setting, property_info->property_name);
+
+ if (!nmc_string_to_ternary(value, &val, error))
+ return FALSE;
+
+ g_object_set(setting, property_info->property_name, (int) val, NULL);
+ return TRUE;
+}
+
static gboolean _set_fcn_gobject_int(ARGS_SET_FCN)
{
int errsv;
@@ -1705,6 +1722,28 @@ static const char *const *_complete_fcn_gobject_bool(ARGS_COMPLETE_FCN)
return v;
}
+static const char *const *_complete_fcn_gobject_ternary(ARGS_COMPLETE_FCN)
+{
+ static const char *const v[] = {
+ "on",
+ "off",
+ "1",
+ "0",
+ "-1",
+ "yes",
+ "no",
+ "unknown",
+ "true",
+ "false",
+ "default",
+ NULL,
+ };
+
+ if (!text || !text[0])
+ return &v[8];
+ return v;
+}
+
static const char *const *_complete_fcn_gobject_devices(ARGS_COMPLETE_FCN)
{
NMDevice *const *devices = NULL;
@@ -4426,6 +4465,13 @@ static const NMMetaPropertyType _pt_gobject_bool = {
.complete_fcn = _complete_fcn_gobject_bool,
};
+_nm_unused
+static const NMMetaPropertyType _pt_gobject_ternary = {
+ .get_fcn = _get_fcn_gobject_enum,
+ .set_fcn = _set_fcn_gobject_ternary,
+ .complete_fcn = _complete_fcn_gobject_ternary,
+};
+
static const NMMetaPropertyType _pt_gobject_int = {
.get_fcn = _get_fcn_gobject_int,
.set_fcn = _set_fcn_gobject_int,