summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2019-04-23 21:35:19 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2019-05-06 10:10:00 +0200
commiteb724293c25038c7e0f0d6789af2cea11da176eb (patch)
tree0a48154f0a864621e2b9c4bfa26191c002d5e8bc
parent78b9448b69d1e511aab9f24f4da8a6731c2dc7ee (diff)
downloadNetworkManager-eb724293c25038c7e0f0d6789af2cea11da176eb.tar.gz
cli: allow completing filenames
Allow the completion function to indicate that the word should be completed as a filename by the shell.
-rw-r--r--clients/cli/connections.c23
-rw-r--r--clients/common/nm-meta-setting-access.c2
-rw-r--r--clients/common/nm-meta-setting-access.h1
-rw-r--r--clients/common/nm-meta-setting-desc.c4
-rw-r--r--clients/common/nm-meta-setting-desc.h2
5 files changed, 24 insertions, 8 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 282cbe06f0..4b484e7bee 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -3785,6 +3785,7 @@ _meta_abstract_complete (const NMMetaAbstractInfo *abstract_info, const char *te
nmc_meta_environment_arg,
&ctx,
text,
+ NULL,
&values_to_free);
if (values)
return values_to_free ?: g_strdupv ((char **) values);
@@ -4525,11 +4526,12 @@ run_rl_generator (rl_compentry_func_t *generator_func, const char *prefix)
}
static gboolean
-complete_option (const NMMetaAbstractInfo *abstract_info, const char *prefix, NMConnection *context_connection)
+complete_option (NmCli *nmc, const NMMetaAbstractInfo *abstract_info, const char *prefix, NMConnection *context_connection)
{
const OptionInfo *candidate;
const char *const*values;
gs_strfreev char **values_to_free = NULL;
+ gboolean complete_filename = FALSE;
const NMMetaOperationContext ctx = {
.connection = context_connection,
};
@@ -4539,7 +4541,12 @@ complete_option (const NMMetaAbstractInfo *abstract_info, const char *prefix, NM
nmc_meta_environment_arg,
&ctx,
prefix,
+ &complete_filename,
&values_to_free);
+ if (complete_filename) {
+ nmc->return_value = NMC_RESULT_COMPLETE_FILE;
+ return TRUE;
+ }
if (values) {
for (; values[0]; values++)
g_print ("%s\n", values[0]);
@@ -4556,13 +4563,13 @@ complete_option (const NMMetaAbstractInfo *abstract_info, const char *prefix, NM
}
static void
-complete_property (const char *setting_name, const char *property, const char *prefix, NMConnection *connection)
+complete_property (NmCli *nmc, const char *setting_name, const char *property, const char *prefix, NMConnection *connection)
{
const NMMetaPropertyInfo *property_info;
property_info = nm_meta_property_info_find_by_name (setting_name, property);
if (property_info)
- complete_option ((const NMMetaAbstractInfo *) property_info, prefix, connection);
+ complete_option (nmc, (const NMMetaAbstractInfo *) property_info, prefix, connection);
}
/*****************************************************************************/
@@ -4652,8 +4659,10 @@ nmc_read_connection_properties (NmCli *nmc,
if (!get_value (&value, argc, argv, option, error))
return FALSE;
- if (!*argc && nmc->complete)
- complete_property (setting, strv[1], value ?: "", connection);
+ if (!*argc && nmc->complete) {
+ complete_property (nmc, setting, strv[1], value ?: "", connection);
+ return TRUE;
+ }
if (!set_property (nmc->client, connection, setting_name, strv[1], value, modifier, error))
return FALSE;
@@ -4734,7 +4743,7 @@ nmc_read_connection_properties (NmCli *nmc,
return FALSE;
if (!*argc && nmc->complete)
- complete_option (chosen, value ?: "", connection);
+ complete_option (nmc, chosen, value ?: "", connection);
if (!set_option (nmc, connection, chosen, value, error))
return FALSE;
@@ -8863,7 +8872,7 @@ do_connection_import (NmCli *nmc, int argc, char **argv)
if ( argc == 1
&& nmc->complete) {
nmc_complete_strings (*argv, "wireguard");
- complete_option ((const NMMetaAbstractInfo *) nm_meta_property_info_vpn_service_type,
+ complete_option (nmc, (const NMMetaAbstractInfo *) nm_meta_property_info_vpn_service_type,
*argv,
NULL);
}
diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c
index 8399f29db1..ce5cd331c8 100644
--- a/clients/common/nm-meta-setting-access.c
+++ b/clients/common/nm-meta-setting-access.c
@@ -273,6 +273,7 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
gpointer environment_user_data,
const NMMetaOperationContext *operation_context,
const char *text,
+ gboolean *out_complete_filename,
char ***out_to_free)
{
const char *const*values;
@@ -292,6 +293,7 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
environment_user_data,
operation_context,
text,
+ out_complete_filename,
out_to_free);
nm_assert (!*out_to_free || values == (const char *const*) *out_to_free);
diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h
index ec1c2ba00a..38f22c7a49 100644
--- a/clients/common/nm-meta-setting-access.h
+++ b/clients/common/nm-meta-setting-access.h
@@ -69,6 +69,7 @@ const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abst
gpointer environment_user_data,
const NMMetaOperationContext *operation_context,
const char *text,
+ gboolean *out_complete_filename,
char ***out_to_free);
/*****************************************************************************/
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 858c8a5312..d70cf3c9a1 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -657,7 +657,7 @@ _env_warn_fcn (const NMMetaEnvironment *environment,
const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, GError **error
#define ARGS_COMPLETE_FCN \
- const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, const char *text, char ***out_to_free
+ const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, const char *text, gboolean *out_complete_filename, char ***out_to_free
#define ARGS_VALUES_FCN \
const NMMetaPropertyInfo *property_info, char ***out_to_free
@@ -8131,6 +8131,7 @@ _meta_type_property_info_complete_fcn (const NMMetaAbstractInfo *abstract_info,
gpointer environment_user_data,
const NMMetaOperationContext *operation_context,
const char *text,
+ gboolean *out_complete_filename,
char ***out_to_free)
{
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
@@ -8143,6 +8144,7 @@ _meta_type_property_info_complete_fcn (const NMMetaAbstractInfo *abstract_info,
environment_user_data,
operation_context,
text,
+ out_complete_filename,
out_to_free);
}
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index 2178f747bb..f075439b70 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -221,6 +221,7 @@ struct _NMMetaPropertyType {
gpointer environment_user_data,
const NMMetaOperationContext *operation_context,
const char *text,
+ gboolean *out_complete_filename,
char ***out_to_free);
/* Whether set_fcn() supports the '-' modifier. That is, whether the property
@@ -451,6 +452,7 @@ struct _NMMetaType {
gpointer environment_user_data,
const NMMetaOperationContext *operation_context,
const char *text,
+ gboolean *out_complete_filename,
char ***out_to_free);
};