mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
cli: allow specifying the connection by its filename
This is handy for users who configure NetworkManager by dropping files into /etc.
This commit is contained in:
parent
386129d92b
commit
d52573d125
|
@ -384,7 +384,7 @@ print_dhcp_config (NMDhcpConfig *dhcp,
|
|||
/*
|
||||
* nmc_find_connection:
|
||||
* @connections: array of NMConnections to search in
|
||||
* @filter_type: "id", "uuid", "path" or %NULL
|
||||
* @filter_type: "id", "uuid", "path", "filename", or %NULL
|
||||
* @filter_val: connection to find (connection name, UUID or path)
|
||||
* @out_result: if not NULL, attach all matching connection to this
|
||||
* list. If necessary, a new array will be allocated. If the array
|
||||
|
@ -452,6 +452,14 @@ nmc_find_connection (const GPtrArray *connections,
|
|||
goto found;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (filter_type, NULL, "filename")) {
|
||||
v = nm_remote_connection_get_filename (NM_REMOTE_CONNECTION (connections->pdata[i]));
|
||||
if (complete && (filter_type || *filter_val))
|
||||
nmc_complete_strings (filter_val, v, NULL);
|
||||
if (nm_streq0 (filter_val, v))
|
||||
goto found;
|
||||
}
|
||||
|
||||
continue;
|
||||
found:
|
||||
if (!out_result)
|
||||
|
@ -523,6 +531,14 @@ nmc_find_active_connection (const GPtrArray *active_cons,
|
|||
goto found;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (filter_type, NULL, "filename")) {
|
||||
v = nm_remote_connection_get_filename (con);
|
||||
if (complete && (filter_type || *filter_val))
|
||||
nmc_complete_strings (filter_val, v, NULL);
|
||||
if (nm_streq0 (filter_val, v))
|
||||
goto found;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (filter_type, NULL, "apath")) {
|
||||
v = nm_object_get_path (NM_OBJECT (candidate));
|
||||
v_num = nm_utils_dbus_path_get_last_component (v);
|
||||
|
|
|
@ -1838,9 +1838,9 @@ get_connection (NmCli *nmc,
|
|||
}
|
||||
|
||||
if (*argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (**argv, "id", "uuid", "path", NULL);
|
||||
nmc_complete_strings (**argv, "id", "uuid", "path", "filename", NULL);
|
||||
|
||||
if (NM_IN_STRSET (**argv, "id", "uuid", "path")) {
|
||||
if (NM_IN_STRSET (**argv, "id", "uuid", "path", "filename")) {
|
||||
if (*argc == 1) {
|
||||
if (!nmc->complete) {
|
||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
|
@ -1981,7 +1981,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
|
|||
char **argv_cp = argv;
|
||||
|
||||
do {
|
||||
if (NM_IN_STRSET (*argv_cp, "id", "uuid", "path", "apath")) {
|
||||
if (NM_IN_STRSET (*argv_cp, "id", "uuid", "path", "filename", "apath")) {
|
||||
argc_cp--;
|
||||
argv_cp++;
|
||||
}
|
||||
|
@ -1999,9 +1999,9 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
|
|||
guint i_found_cons;
|
||||
|
||||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (*argv, "id", "uuid", "path", "apath", NULL);
|
||||
nmc_complete_strings (*argv, "id", "uuid", "path", "filename", "apath", NULL);
|
||||
|
||||
if (NM_IN_STRSET (*argv, "id", "uuid", "path", "apath")) {
|
||||
if (NM_IN_STRSET (*argv, "id", "uuid", "path", "filename", "apath")) {
|
||||
selector = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -2948,9 +2948,9 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
|||
const char *selector = NULL;
|
||||
|
||||
if (arg_num == 1 && nmc->complete)
|
||||
nmc_complete_strings (*arg_ptr, "id", "uuid", "path", "apath", NULL);
|
||||
nmc_complete_strings (*arg_ptr, "id", "uuid", "path", "filename", "apath", NULL);
|
||||
|
||||
if (NM_IN_STRSET (*arg_ptr, "id", "uuid", "path", "apath")) {
|
||||
if (NM_IN_STRSET (*arg_ptr, "id", "uuid", "path", "filename", "apath")) {
|
||||
selector = *arg_ptr;
|
||||
arg_num--;
|
||||
arg_ptr++;
|
||||
|
@ -7949,6 +7949,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||
const char *con_id = NULL;
|
||||
const char *con_uuid = NULL;
|
||||
const char *con_path = NULL;
|
||||
const char *con_filename = NULL;
|
||||
const char *selector = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
GError *err1 = NULL;
|
||||
|
@ -7957,11 +7958,12 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||
{ "id", TRUE, &con_id, FALSE },
|
||||
{ "uuid", TRUE, &con_uuid, FALSE },
|
||||
{ "path", TRUE, &con_path, FALSE },
|
||||
{ "filename", TRUE, &con_filename, FALSE },
|
||||
{ NULL } };
|
||||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (*argv, "type", "con-name", "id", "uuid", "path", NULL);
|
||||
nmc_complete_strings (*argv, "type", "con-name", "id", "uuid", "path", "filename", NULL);
|
||||
|
||||
nmc->return_value = NMC_RESULT_SUCCESS;
|
||||
|
||||
|
@ -7983,20 +7985,23 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||
connections = nm_client_get_connections (nmc->client);
|
||||
|
||||
if (!con) {
|
||||
if (con_id && !con_uuid && !con_path) {
|
||||
if (con_id && !con_uuid && !con_path && !con_filename) {
|
||||
con = con_id;
|
||||
selector = "id";
|
||||
} else if (con_uuid && !con_id && !con_path) {
|
||||
} else if (con_uuid && !con_id && !con_path && !con_filename) {
|
||||
con = con_uuid;
|
||||
selector = "uuid";
|
||||
} else if (con_path && !con_id && !con_uuid) {
|
||||
} else if (con_path && !con_id && !con_uuid && !con_filename) {
|
||||
con = con_path;
|
||||
selector = "path";
|
||||
} else if (!con_path && !con_id && !con_uuid) {
|
||||
} else if (con_filename && !con_path && !con_id && !con_uuid) {
|
||||
con = con_filename;
|
||||
selector = "filename";
|
||||
} else if (!con_path && !con_id && !con_uuid && !con_filename) {
|
||||
/* no-op */
|
||||
} else {
|
||||
g_string_printf (nmc->return_text,
|
||||
_("Error: only one of 'id', uuid, or 'path' can be provided."));
|
||||
_("Error: only one of 'id', 'filename', uuid, or 'path' can be provided."));
|
||||
NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ location: clients/tests/test-client.py:725:test_003()/9
|
|||
cmd: $NMCLI --complete-args -f ALL c s ''
|
||||
lang: C
|
||||
returncode: 0
|
||||
stdout: 64 bytes
|
||||
stdout: 73 bytes
|
||||
>>>
|
||||
|
||||
--active
|
||||
|
@ -11,6 +11,7 @@ apath
|
|||
con-1
|
||||
con-xx1
|
||||
ethernet
|
||||
filename
|
||||
help
|
||||
id
|
||||
path
|
||||
|
|
|
@ -2,7 +2,7 @@ location: clients/tests/test-client.py:725:test_003()/10
|
|||
cmd: $NMCLI --complete-args -f ALL c s ''
|
||||
lang: pl_PL.UTF-8
|
||||
returncode: 0
|
||||
stdout: 64 bytes
|
||||
stdout: 73 bytes
|
||||
>>>
|
||||
|
||||
--active
|
||||
|
@ -11,6 +11,7 @@ apath
|
|||
con-1
|
||||
con-xx1
|
||||
ethernet
|
||||
filename
|
||||
help
|
||||
id
|
||||
path
|
||||
|
|
Loading…
Reference in a new issue