cli: remove '--nowait' and '--timeout' options and use global '--wait' instead

'--wait 0' corresponds to '--nowait'
'--wait n' for n > 0 corresponds to '--timeout n'
This commit is contained in:
Jiří Klimeš
2013-05-14 12:43:43 +02:00
parent 7d55426992
commit fa6ecaed32
2 changed files with 27 additions and 79 deletions

View File

@@ -199,9 +199,9 @@ usage (void)
" show configured [[ id | uuid | path ] <ID>]\n\n" " show configured [[ id | uuid | path ] <ID>]\n\n"
" show active [[ id | uuid | path | apath ] <ID>]\n\n" " show active [[ id | uuid | path | apath ] <ID>]\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>] [--nowait] [--timeout <timeout>]\n\n" " up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n"
#else #else
" up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [--nowait] [--timeout <timeout>]\n\n" " up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>]\n\n"
#endif #endif
" down [ id | uuid | path | apath ] <ID>\n\n" " down [ id | uuid | path | apath ] <ID>\n\n"
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n" " add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
@@ -1473,17 +1473,18 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
const char *ifname = NULL; const char *ifname = NULL;
const char *ap = NULL; const char *ap = NULL;
const char *nsp = NULL; const char *nsp = NULL;
gboolean wait = TRUE;
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; const char *name;
char *line = NULL; char *line = NULL;
/* Set default timeout for connection activation. It can take quite a long time. /*
* Using 90 seconds. * Set default timeout for connection activation.
* Activation can take quite a long time, use 90 seconds.
*/ */
nmc->timeout = 90; if (nmc->timeout == -1)
nmc->timeout = 90;
if (argc == 0) { if (argc == 0) {
if (nmc->ask) { if (nmc->ask) {
@@ -1551,23 +1552,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
nsp = *argv; nsp = *argv;
} }
#endif #endif
else if (strcmp (*argv, "--nowait") == 0) { else {
wait = FALSE;
} else if (strcmp (*argv, "--timeout") == 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;
goto error;
}
errno = 0;
nmc->timeout = strtol (*argv, NULL, 10);
if (errno || nmc->timeout < 0) {
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
} else {
fprintf (stderr, _("Unknown parameter: %s\n"), *argv); fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
} }
@@ -1609,7 +1594,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
* active_connection_state_cb() is called. That gives NM time to check our permissions * active_connection_state_cb() is called. That gives NM time to check our permissions
* and we can follow activation progress. * and we can follow activation progress.
*/ */
nmc->nowait_flag = !wait; nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
info = g_malloc0 (sizeof (ActivateConnectionInfo)); info = g_malloc0 (sizeof (ActivateConnectionInfo));

View File

@@ -263,10 +263,10 @@ usage (void)
#endif #endif
" status\n\n" " status\n\n"
" show [<ifname>]\n\n" " show [<ifname>]\n\n"
" disconnect <ifname> [--nowait] [--timeout <timeout>]\n\n" " disconnect <ifname>\n\n"
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n" " wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n"
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>] [bssid <BSSID>] [name <name>]\n\n" " wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>] [bssid <BSSID>] [name <name>]\n\n"
" [--private] [--nowait] [--timeout <timeout>]\n\n" " [--private]\n\n"
" wifi rescan [[ifname] <ifname>]\n\n" " wifi rescan [[ifname] <ifname>]\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" wimax [list [ifname <ifname>] [nsp <name>]]\n\n" " wimax [list [ifname <ifname>] [nsp <name>]]\n\n"
@@ -1161,11 +1161,11 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
NMDevice *device = NULL; NMDevice *device = NULL;
const char *ifname = NULL; const char *ifname = NULL;
char *ifname_ask = NULL; char *ifname_ask = NULL;
gboolean wait = TRUE;
int i; int i;
/* Set default timeout for disconnect operation */ /* Set default timeout for disconnect operation. */
nmc->timeout = 10; if (nmc->timeout == -1)
nmc->timeout = 10;
if (argc == 0) { if (argc == 0) {
if (nmc->ask) { if (nmc->ask) {
@@ -1186,37 +1186,14 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error; goto error;
} }
next_arg (&argc, &argv);
while (argc > 0) { if (next_arg (&argc, &argv) == 0) {
if (strcmp (*argv, "--nowait") == 0) { g_string_printf (nmc->return_text, _("Error: extra argument not allowed: '%s'."), *argv);
wait = FALSE; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
} else if (strcmp (*argv, "--timeout") == 0) { 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;
}
errno = 0;
nmc->timeout = strtol (*argv, NULL, 10);
if (errno || nmc->timeout < 0) {
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
} else {
g_string_printf (nmc->return_text, _("Error: unknown argument '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
next_arg (&argc, &argv);
} }
nmc->get_client (nmc); nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) { if (!nm_client_get_manager_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
@@ -1242,9 +1219,11 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
goto error; goto error;
} }
/* Use nowait_flag instead of should_wait because exitting has to be postponed till disconnect_device_cb() /*
* is called, giving NM time to check our permissions */ * Use nowait_flag instead of should_wait, because exiting has to be postponed
nmc->nowait_flag = !wait; * till disconnect_device_cb() is called, giving NM time to check our permissions.
*/
nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
nm_device_disconnect (device, disconnect_device_cb, nmc); nm_device_disconnect (device, disconnect_device_cb, nmc);
@@ -1646,7 +1625,6 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
const char *password = NULL; const char *password = NULL;
const char *con_name = NULL; const char *con_name = NULL;
gboolean private = FALSE; gboolean private = FALSE;
gboolean wait = TRUE;
gboolean wep_passphrase = FALSE; gboolean wep_passphrase = FALSE;
GByteArray *bssid1_arr = NULL; GByteArray *bssid1_arr = NULL;
GByteArray *bssid2_arr = NULL; GByteArray *bssid2_arr = NULL;
@@ -1655,8 +1633,9 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
char *ssid_ask = NULL; char *ssid_ask = NULL;
char *passwd_ask = NULL; char *passwd_ask = NULL;
/* Default timeout for waiting for operation completion */ /* Set default timeout waiting for operation completion. */
nmc->timeout = 90; if (nmc->timeout == -1)
nmc->timeout = 90;
/* Get the first compulsory argument (SSID or BSSID) */ /* Get the first compulsory argument (SSID or BSSID) */
if (argc > 0) { if (argc > 0) {
@@ -1734,22 +1713,6 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
con_name = *argv; con_name = *argv;
} else if (strcmp (*argv, "--private") == 0) { } else if (strcmp (*argv, "--private") == 0) {
private = TRUE; private = TRUE;
} else if (strcmp (*argv, "--nowait") == 0) {
wait = FALSE;
} else if (strcmp (*argv, "--timeout") == 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;
goto error;
}
errno = 0;
nmc->timeout = strtol (*argv, NULL, 10);
if (errno || nmc->timeout < 0) {
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
} else { } else {
fprintf (stderr, _("Unknown parameter: %s\n"), *argv); fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
} }
@@ -1884,7 +1847,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
* We have to delay exit after add_and_activate_cb() is called, even if * We have to delay exit after add_and_activate_cb() is called, even if
* the user doesn't want to wait, in order to give NM time to check our * the user doesn't want to wait, in order to give NM time to check our
* permissions. */ * permissions. */
nmc->nowait_flag = !wait; nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE; nmc->should_wait = TRUE;
info = g_malloc0 (sizeof (AddAndActivateInfo)); info = g_malloc0 (sizeof (AddAndActivateInfo));