cli: allow editing existing connections in interactive editor
So the syntax is now: nmcli con edit [id | uuid | path ] <ID> - for editing an existing connection nmcli con edit [type <new connection type>] [con-name <new connection name>] - for adding a new connection
This commit is contained in:
@@ -210,7 +210,7 @@ usage (void)
|
|||||||
#endif
|
#endif
|
||||||
" down [ id | uuid | path | apath ] <ID>\n\n"
|
" down [ id | uuid | path | apath ] <ID>\n\n"
|
||||||
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
|
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
|
||||||
" edit [type <new_con_type>] [con-name <new_con_name>]\n\n"
|
" edit [ id | uuid | path ] <ID> | [type <new_con_type>] [con-name <new_con_name>]\n\n"
|
||||||
" delete [ id | uuid | path ] <ID>\n\n"
|
" delete [ id | uuid | path ] <ID>\n\n"
|
||||||
" reload\n\n\n"
|
" reload\n\n\n"
|
||||||
));
|
));
|
||||||
@@ -4184,22 +4184,34 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
char *type_ask = NULL;
|
char *type_ask = NULL;
|
||||||
const char *con_name = NULL;
|
const char *con_name = NULL;
|
||||||
|
const char *con = NULL;
|
||||||
|
const char *con_id = NULL;
|
||||||
|
const char *con_uuid = NULL;
|
||||||
|
const char *con_path = NULL;
|
||||||
|
const char *selector = NULL;
|
||||||
char *tmp_str;
|
char *tmp_str;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GError *err1 = NULL;
|
GError *err1 = NULL;
|
||||||
GModule *edit_lib_module = NULL;
|
GModule *edit_lib_module = NULL;
|
||||||
nmc_arg_t exp_args[] = { {"type", TRUE, &type, FALSE},
|
nmc_arg_t exp_args[] = { {"type", TRUE, &type, FALSE},
|
||||||
{"con-name", TRUE, &con_name, FALSE},
|
{"con-name", TRUE, &con_name, FALSE},
|
||||||
|
{"id", TRUE, &con_id, FALSE},
|
||||||
|
{"uuid", TRUE, &con_uuid, FALSE},
|
||||||
|
{"path", TRUE, &con_path, FALSE},
|
||||||
{NULL} };
|
{NULL} };
|
||||||
|
|
||||||
nmc->return_value = NMC_RESULT_SUCCESS;
|
nmc->return_value = NMC_RESULT_SUCCESS;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
con = *argv;
|
||||||
|
else {
|
||||||
if (!nmc_parse_args (exp_args, TRUE, &argc, &argv, &error)) {
|
if (!nmc_parse_args (exp_args, TRUE, &argc, &argv, &error)) {
|
||||||
g_string_assign (nmc->return_text, error->message);
|
g_string_assign (nmc->return_text, error->message);
|
||||||
nmc->return_value = error->code;
|
nmc->return_value = error->code;
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Load line editing library */
|
/* Load line editing library */
|
||||||
if (!(edit_lib_module = load_cmd_line_edit_lib ())) {
|
if (!(edit_lib_module = load_cmd_line_edit_lib ())) {
|
||||||
@@ -4214,6 +4226,54 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||||||
edit_lib_symbols.rl_startup_hook_x = NULL;
|
edit_lib_symbols.rl_startup_hook_x = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!con) {
|
||||||
|
if (con_id && !con_uuid && !con_path) {
|
||||||
|
con = con_id;
|
||||||
|
selector = "id";
|
||||||
|
} else if (con_uuid && !con_id && !con_path) {
|
||||||
|
con = con_uuid;
|
||||||
|
selector = "uuid";
|
||||||
|
} else if (con_path && !con_id && !con_uuid) {
|
||||||
|
con = con_path;
|
||||||
|
selector = "path";
|
||||||
|
} else if (!con_path && !con_id && !con_uuid) {
|
||||||
|
/* no-op */
|
||||||
|
} else {
|
||||||
|
g_string_printf (nmc->return_text,
|
||||||
|
_("Error: only one of 'id', uuid, or 'path' can be provided."));
|
||||||
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (con) {
|
||||||
|
/* Existing connection */
|
||||||
|
NMConnection *found_con;
|
||||||
|
|
||||||
|
found_con = find_connection (nmc->system_connections, selector, con);
|
||||||
|
if (!found_con) {
|
||||||
|
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con);
|
||||||
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Duplicate the connection and use that so that we need not
|
||||||
|
* differentiate existing vs. new later
|
||||||
|
*/
|
||||||
|
connection = nm_connection_duplicate (found_con);
|
||||||
|
|
||||||
|
s_con = nm_connection_get_setting_connection (connection);
|
||||||
|
g_assert (s_con);
|
||||||
|
connection_type = nm_setting_connection_get_connection_type (s_con);
|
||||||
|
|
||||||
|
if (type)
|
||||||
|
printf (_("Warning: editing existing connection '%s'; 'type' argument is ignored\n"),
|
||||||
|
nm_connection_get_id (connection));
|
||||||
|
if (con_name)
|
||||||
|
printf (_("Warning: editing existing connection '%s'; 'con-name' argument is ignored\n"),
|
||||||
|
nm_connection_get_id (connection));
|
||||||
|
} else {
|
||||||
|
/* New connection */
|
||||||
connection_type = check_valid_name (type, nmc_valid_connection_types, &err1);
|
connection_type = check_valid_name (type, nmc_valid_connection_types, &err1);
|
||||||
tmp_str = get_valid_options_string (nmc_valid_connection_types);
|
tmp_str = get_valid_options_string (nmc_valid_connection_types);
|
||||||
|
|
||||||
@@ -4254,10 +4314,14 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
/* Initialize the new connection so that it is valid from the start */
|
/* Initialize the new connection so that it is valid from the start */
|
||||||
editor_init_new_connection (nmc, connection);
|
editor_init_new_connection (nmc, connection);
|
||||||
|
}
|
||||||
|
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
printf (_("===| nmcli interactive connection editor |==="));
|
printf (_("===| nmcli interactive connection editor |==="));
|
||||||
printf ("\n\n");
|
printf ("\n\n");
|
||||||
|
if (con)
|
||||||
|
printf (_("Editing existing '%s' connection: '%s'"), connection_type, con);
|
||||||
|
else
|
||||||
printf (_("Adding a new '%s' connection"), connection_type);
|
printf (_("Adding a new '%s' connection"), connection_type);
|
||||||
printf ("\n\n");
|
printf ("\n\n");
|
||||||
printf (_("Type 'help' or '?' for available commands."));
|
printf (_("Type 'help' or '?' for available commands."));
|
||||||
|
Reference in New Issue
Block a user