cli: 'connection up' - ask for a connection name if not provided
when '--ask' switch is used
This commit is contained in:

committed by
Dan Williams

parent
b0bee192e8
commit
97dbf98cdd
@@ -1374,6 +1374,8 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean is_virtual = FALSE;
|
gboolean is_virtual = FALSE;
|
||||||
const char *selector = NULL;
|
const char *selector = NULL;
|
||||||
|
const char *name;
|
||||||
|
char *line = NULL;
|
||||||
|
|
||||||
/* Set default timeout for connection activation. It can take quite a long time.
|
/* Set default timeout for connection activation. It can take quite a long time.
|
||||||
* Using 90 seconds.
|
* Using 90 seconds.
|
||||||
@@ -1381,27 +1383,36 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
nmc->timeout = 90;
|
nmc->timeout = 90;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
|
if (nmc->ask) {
|
||||||
|
line = nmc_get_user_input (_("Connection (name, UUID, or path): "));
|
||||||
|
name = line ? line : "";
|
||||||
|
// TODO: enhancement: when just Enter is pressed (line is NULL), list
|
||||||
|
// available connections so that the user can select one
|
||||||
|
} else {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if ( strcmp (*argv, "id") == 0
|
if ( strcmp (*argv, "id") == 0
|
||||||
|| strcmp (*argv, "uuid") == 0
|
|| strcmp (*argv, "uuid") == 0
|
||||||
|| strcmp (*argv, "path") == 0) {
|
|| strcmp (*argv, "path") == 0) {
|
||||||
|
|
||||||
selector = *argv;
|
selector = *argv;
|
||||||
if (next_arg (&argc, &argv) != 0) {
|
if (next_arg (&argc, &argv) != 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;
|
||||||
}
|
}
|
||||||
|
name = *argv;
|
||||||
|
}
|
||||||
|
name = *argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = find_connection (nmc->system_connections, selector, *argv);
|
connection = find_connection (nmc->system_connections, selector, name);
|
||||||
|
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), *argv);
|
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), name);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@@ -1513,9 +1524,11 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
if (nmc->print_output == NMC_PRINT_PRETTY)
|
if (nmc->print_output == NMC_PRINT_PRETTY)
|
||||||
progress_id = g_timeout_add (120, progress_cb, "preparing");
|
progress_id = g_timeout_add (120, progress_cb, "preparing");
|
||||||
|
|
||||||
|
g_free (line);
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
error:
|
error:
|
||||||
nmc->should_wait = FALSE;
|
nmc->should_wait = FALSE;
|
||||||
|
g_free (line);
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user