cli: 'connection down' - ask for a connection name if not provided

when '--ask' switch is used
This commit is contained in:
Jiří Klimeš
2012-11-22 13:32:21 +01:00
committed by Dan Williams
parent 97dbf98cdd
commit 786ba05bfa

View File

@@ -1537,12 +1537,23 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
{ {
NMActiveConnection *active; NMActiveConnection *active;
const GPtrArray *active_cons; const GPtrArray *active_cons;
char *line = NULL;
char **arg_arr = NULL;
char **arg_ptr = argv;
int arg_num = argc;
if (argc == 0) { if (argc == 0) {
if (nmc->ask) {
line = nmc_get_user_input (_("Connection (name, UUID, or path): "));
nmc_string_to_arg_array (line, "", &arg_arr, &arg_num);
arg_ptr = arg_arr;
}
if (arg_num == 0) {
g_string_printf (nmc->return_text, _("Error: No connection specified.")); g_string_printf (nmc->return_text, _("Error: No connection specified."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error; goto error;
} }
}
/* create NMClient */ /* create NMClient */
nmc->get_client (nmc); nmc->get_client (nmc);
@@ -1555,33 +1566,32 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
/* Get active connections */ /* Get active connections */
active_cons = nm_client_get_active_connections (nmc->client); active_cons = nm_client_get_active_connections (nmc->client);
while (argc > 0) { while (arg_num > 0) {
const char *selector = NULL; const char *selector = NULL;
if ( strcmp (*argv, "id") == 0 if ( strcmp (*arg_ptr, "id") == 0
|| strcmp (*argv, "uuid") == 0 || strcmp (*arg_ptr, "uuid") == 0
|| strcmp (*argv, "path") == 0 || strcmp (*arg_ptr, "path") == 0
|| strcmp (*argv, "apath") == 0) { || strcmp (*arg_ptr, "apath") == 0) {
selector = *argv; selector = *arg_ptr;
if (next_arg (&argc, &argv) != 0) { if (next_arg (&arg_num, &arg_ptr) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); g_string_printf (nmc->return_text, _("Error: %s argument is missing."), selector);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error; goto error;
} }
} }
active = find_active_connection (active_cons, nmc->system_connections, selector, *argv); active = find_active_connection (active_cons, nmc->system_connections, selector, *arg_ptr);
if (active) { if (active) {
nm_client_deactivate_connection (nmc->client, active); nm_client_deactivate_connection (nmc->client, active);
} else { } else {
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *argv); g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
goto error; goto error;
} }
argc--; next_arg (&arg_num, &arg_ptr);
argv++;
} }
// FIXME: do something better then sleep() // FIXME: do something better then sleep()
@@ -1590,6 +1600,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
error: error:
nmc->should_wait = FALSE; nmc->should_wait = FALSE;
g_strfreev (arg_arr);
return nmc->return_value; return nmc->return_value;
} }