cli: make id|uuid optional for 'nmcli connection up'

and also allow identifying connetions with 'path' that accepts either the whole
D-Dus path or just an index.

nmcli connection up [id|uuid|path] <ID>

Examples:
nmcli connection up "My Home Wi-Fi"
nmcli connection up id "My Home Wi-Fi"
nmcli connection up path /org/freedesktop/NetworkManager/Settings/18
nmcli connection up path 18

Note:
In order to be able to identify connections with just index number, the 'path'
keyword has to be provided.
This commit is contained in:
Jiří Klimeš
2012-11-19 12:31:33 +01:00
committed by Dan Williams
parent 4eef48d4aa
commit 6d5a88f02c

View File

@@ -197,9 +197,9 @@ usage (void)
" list [[id|uuid|path] <ID>]\n" " list [[id|uuid|path] <ID>]\n"
" status [[id|uuid|path|apath] <ID>]\n" " status [[id|uuid|path|apath] <ID>]\n"
#if WITH_WIMAX #if WITH_WIMAX
" up id <id> | uuid <id> [iface <iface>] [ap <BSSID>] [nsp <name>] [--nowait] [--timeout <timeout>]\n" " up [id|uuid|path] <ID> [iface <iface>] [ap <BSSID>] [nsp <name>] [--nowait] [--timeout <timeout>]\n"
#else #else
" up id <id> | uuid <id> [iface <iface>] [ap <BSSID>] [--nowait] [--timeout <timeout>]\n" " up [id|uuid|path] <ID> [iface <iface>] [ap <BSSID>] [--nowait] [--timeout <timeout>]\n"
#endif #endif
" down id <id> | uuid <id>\n" " down id <id> | uuid <id>\n"
" delete [id|uuid|path] <ID>\n" " delete [id|uuid|path] <ID>\n"
@@ -1371,36 +1371,45 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
const char *iface = NULL; const char *iface = NULL;
const char *ap = NULL; const char *ap = NULL;
const char *nsp = NULL; const char *nsp = NULL;
gboolean id_specified = FALSE;
gboolean wait = TRUE; gboolean wait = TRUE;
GError *error = NULL; GError *error = NULL;
gboolean is_virtual = FALSE; gboolean is_virtual = FALSE;
const char *selector = 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.
*/ */
nmc->timeout = 90; nmc->timeout = 90;
while (argc > 0) { if (argc == 0) {
if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) { g_string_printf (nmc->return_text, _("Error: No connection specified."));
const char *selector = *argv; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
id_specified = TRUE; goto error;
}
if (next_arg (&argc, &argv) != 0) { if ( strcmp (*argv, "id") == 0
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); || strcmp (*argv, "uuid") == 0
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; || strcmp (*argv, "path") == 0) {
goto error;
}
connection = find_connection (nmc->system_connections, selector, *argv); selector = *argv;
if (next_arg (&argc, &argv) != 0) {
if (!connection) { g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), *argv); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; goto error;
goto error;
}
} }
else if (strcmp (*argv, "iface") == 0) { }
connection = find_connection (nmc->system_connections, selector, *argv);
if (!connection) {
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
goto error;
}
next_arg (&argc, &argv);
while (argc > 0) {
if (strcmp (*argv, "iface") == 0) {
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."), *(argv-1));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
@@ -1453,12 +1462,6 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
argv++; argv++;
} }
if (!id_specified) {
g_string_printf (nmc->return_text, _("Error: id or uuid has to be specified."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
/* create NMClient */ /* create NMClient */
nmc->get_client (nmc); nmc->get_client (nmc);