From 6d5a88f02c154cdf8d7fb4690c5918a090f34e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Mon, 19 Nov 2012 12:31:33 +0100 Subject: [PATCH] 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] 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. --- cli/src/connections.c | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index ad0c46d8f9..ed5b945a93 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -197,9 +197,9 @@ usage (void) " list [[id|uuid|path] ]\n" " status [[id|uuid|path|apath] ]\n" #if WITH_WIMAX - " up id | uuid [iface ] [ap ] [nsp ] [--nowait] [--timeout ]\n" + " up [id|uuid|path] [iface ] [ap ] [nsp ] [--nowait] [--timeout ]\n" #else - " up id | uuid [iface ] [ap ] [--nowait] [--timeout ]\n" + " up [id|uuid|path] [iface ] [ap ] [--nowait] [--timeout ]\n" #endif " down id | uuid \n" " delete [id|uuid|path] \n" @@ -1371,36 +1371,45 @@ do_connection_up (NmCli *nmc, int argc, char **argv) const char *iface = NULL; const char *ap = NULL; const char *nsp = NULL; - gboolean id_specified = FALSE; gboolean wait = TRUE; GError *error = NULL; gboolean is_virtual = FALSE; + const char *selector = NULL; /* Set default timeout for connection activation. It can take quite a long time. * Using 90 seconds. */ nmc->timeout = 90; - while (argc > 0) { - if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) { - const char *selector = *argv; - id_specified = TRUE; + if (argc == 0) { + g_string_printf (nmc->return_text, _("Error: No connection specified.")); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto error; + } - if (next_arg (&argc, &argv) != 0) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto error; - } + if ( strcmp (*argv, "id") == 0 + || strcmp (*argv, "uuid") == 0 + || strcmp (*argv, "path") == 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; - } + selector = *argv; + if (next_arg (&argc, &argv) != 0) { + g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + 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) { g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -1453,12 +1462,6 @@ do_connection_up (NmCli *nmc, int argc, char **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 */ nmc->get_client (nmc);