summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-04-10 16:38:35 +0200
committerThomas Haller <thaller@redhat.com>2017-04-12 14:12:19 +0200
commitcfd9f66ae90573377665bb0a21accc62db94c42e (patch)
tree21f87d39029c541959b1db975c4bfb2e87238483
parent4f19c46a1e642c7d5c6ab6de5b57b8256754277b (diff)
downloadNetworkManager-cfd9f66ae90573377665bb0a21accc62db94c42e.tar.gz
cli: add property completion to meta-data
(not used yet).
-rw-r--r--clients/cli/connections.c18
-rw-r--r--clients/common/nm-meta-setting-access.c65
-rw-r--r--clients/common/nm-meta-setting-access.h4
-rw-r--r--clients/common/nm-meta-setting-desc.c28
-rw-r--r--clients/common/nm-meta-setting-desc.h7
5 files changed, 113 insertions, 9 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 38975fb8c6..943182a6a2 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -3847,13 +3847,6 @@ ensure_settings (NMConnection *connection, const NameItem *item)
/*----------------------------------------------------------------------------*/
static char *
-gen_func_slave_type (const char *text, int state)
-{
- const char *words[] = { "bond", "team", "bridge", NULL };
- return nmc_rl_gen_func_basic (text, state, words);
-}
-
-static char *
gen_func_vpn_types (const char *text, int state)
{
gs_strfreev char **plugin_names = NULL;
@@ -4306,7 +4299,6 @@ _meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info)
OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_AUTOCONNECT, "autoconnect", NULL, gen_func_bool_values_l10n),
OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_INTERFACE_NAME, "ifname", set_connection_iface, nmc_rl_gen_func_ifnames),
OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_MASTER, "master", set_connection_master, gen_func_master_ifnames),
- OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_SLAVE_TYPE, "slave-type", NULL, gen_func_slave_type),
OPTION_INFO (INFINIBAND, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "transport-mode", NULL, gen_func_ib_type),
OPTION_INFO (WIRELESS, NM_SETTING_WIRELESS_MODE, "mode", NULL, gen_func_wifi_mode),
OPTION_INFO (BLUETOOTH, NM_SETTING_BLUETOOTH_TYPE, "bt-type", set_bluetooth_type, gen_func_bt_type),
@@ -4462,6 +4454,15 @@ static void
complete_option (const NMMetaAbstractInfo *abstract_info, const gchar *prefix)
{
const OptionInfo *candidate;
+ const char *const*values;
+ gs_strfreev char **values_to_free = NULL;
+
+ values = nm_meta_abstract_info_complete (abstract_info, prefix, &values_to_free);
+ if (values) {
+ for (; values[0]; values++)
+ g_print ("%s\n", values[0]);
+ return;
+ }
candidate = _meta_abstract_get_option_info (abstract_info);
if (candidate && candidate->generator_func)
@@ -4513,7 +4514,6 @@ complete_property (const gchar *setting_name, const gchar *property, const gchar
} else if ( strcmp (setting_name, NM_SETTING_VXLAN_SETTING_NAME) == 0
&& strcmp (property, NM_SETTING_VXLAN_PARENT) == 0)
run_rl_generator (nmc_rl_gen_func_ifnames, prefix);
-
}
/*----------------------------------------------------------------------------*/
diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c
index d3843dfef1..e18b03632e 100644
--- a/clients/common/nm-meta-setting-access.c
+++ b/clients/common/nm-meta-setting-access.c
@@ -253,3 +253,68 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
out_flags,
out_to_free);
}
+
+const char *const*
+nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
+ const char *text,
+ char ***out_to_free)
+{
+ const char *const*values;
+ gsize i, j, text_len;
+
+ nm_assert (abstract_info);
+ nm_assert (abstract_info->meta_type);
+ nm_assert (out_to_free && !*out_to_free);
+
+ *out_to_free = NULL;
+
+ if (!abstract_info->meta_type->complete_fcn)
+ return NULL;
+
+ values = abstract_info->meta_type->complete_fcn (abstract_info,
+ text,
+ out_to_free);
+
+ nm_assert (!*out_to_free || values == (const char *const*) *out_to_free);
+
+ if (!text || !text[0] || !values || !values[0])
+ return values;
+
+ /* for convenience, we all the complete_fcn() implementations to
+ * ignore "text". We filter out invalid matches here. */
+
+ text_len = strlen (text);
+
+ if (*out_to_free) {
+ char **v = *out_to_free;
+
+ for (i =0, j = 0; v[i]; i++) {
+ if (strncmp (v[i], text, text_len) != 0)
+ continue;
+ v[j++] = v[i];
+ }
+ v[j++] = NULL;
+ return (const char *const*) *out_to_free;
+ } else {
+ const char *const*v = values;
+ char **r;
+
+ for (i = 0, j = 0; v[i]; i++) {
+ if (strncmp (v[i], text, text_len) != 0)
+ continue;
+ j++;
+ }
+ if (j == i)
+ return values;
+
+ r = g_new (char *, j + 1);
+ v = values;
+ for (i = 0, j = 0; v[i]; i++) {
+ if (strncmp (v[i], text, text_len) != 0)
+ continue;
+ r[j++] = g_strdup (v[i]);
+ }
+ r[j++] = NULL;
+ return (const char *const*) (*out_to_free = r);
+ }
+}
diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h
index 8aec04aced..7a816875cd 100644
--- a/clients/common/nm-meta-setting-access.h
+++ b/clients/common/nm-meta-setting-access.h
@@ -59,6 +59,10 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free);
+const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
+ const char *text,
+ char ***out_to_free);
+
/*****************************************************************************/
#endif /* _NM_META_SETTING_ACCESS_H__ */
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 4393923fc5..aff546d0e6 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -7210,6 +7210,33 @@ _meta_type_property_info_get_nested (const NMMetaAbstractInfo *abstract_info,
return NULL;
}
+static const char *const*
+_meta_type_property_info_complete_fcn (const NMMetaAbstractInfo *abstract_info,
+ const char *text,
+ char ***out_to_free)
+{
+ const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
+
+ nm_assert (out_to_free && !*out_to_free);
+
+ if (info->property_type->complete_fcn) {
+ return info->property_type->complete_fcn (info,
+ text,
+ out_to_free);
+ }
+
+ if (info->property_type->values_fcn) {
+ return info->property_type->values_fcn (info,
+ out_to_free);
+ }
+
+ if ( info->property_typ_data
+ && info->property_typ_data->values_static)
+ return info->property_typ_data->values_static;
+
+ return NULL;
+}
+
const NMMetaType nm_meta_type_setting_info_editor = {
.type_name = "setting_info_editor",
.get_name = _meta_type_setting_info_editor_get_name,
@@ -7222,6 +7249,7 @@ const NMMetaType nm_meta_type_property_info = {
.get_name = _meta_type_property_info_get_name,
.get_nested = _meta_type_property_info_get_nested,
.get_fcn = _meta_type_property_info_get_fcn,
+ .complete_fcn = _meta_type_property_info_complete_fcn,
};
const NMMetaType nm_meta_type_nested_property_info = {
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index 2a967267cd..0339a59d81 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -195,6 +195,10 @@ struct _NMMetaPropertyType {
const char *const*(*values_fcn) (const NMMetaPropertyInfo *property_info,
char ***out_to_free);
+
+ const char *const*(*complete_fcn) (const NMMetaPropertyInfo *property_info,
+ const char *text,
+ char ***out_to_free);
};
struct _NMUtilsEnumValueInfo;
@@ -284,6 +288,9 @@ struct _NMMetaType {
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free);
+ const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info,
+ const char *text,
+ char ***out_to_free);
};
struct _NMMetaAbstractInfo {