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:

committed by
Dan Williams

parent
4eef48d4aa
commit
6d5a88f02c
@@ -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,26 +1371,33 @@ 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 ( strcmp (*argv, "id") == 0
|
||||||
|
|| strcmp (*argv, "uuid") == 0
|
||||||
|
|| strcmp (*argv, "path") == 0) {
|
||||||
|
|
||||||
|
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."), *(argv-1));
|
||||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connection = find_connection (nmc->system_connections, selector, *argv);
|
connection = find_connection (nmc->system_connections, selector, *argv);
|
||||||
|
|
||||||
@@ -1399,8 +1406,10 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
next_arg (&argc, &argv);
|
||||||
else if (strcmp (*argv, "iface") == 0) {
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user