mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
cli: allow next_arg() to move arguments past the last one
This commit is contained in:
parent
dc05592b76
commit
35689c7bd0
|
@ -572,7 +572,7 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
|
|||
NMConnection *con;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return nmc->return_value;
|
||||
}
|
||||
|
@ -1109,7 +1109,7 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
|
|||
NMActiveConnection *acon;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return nmc->return_value;
|
||||
}
|
||||
|
@ -1647,7 +1647,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
id_specified = TRUE;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1662,7 +1662,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
else if (strcmp (*argv, "iface") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1671,7 +1671,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
else if (strcmp (*argv, "ap") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1681,7 +1681,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
#if WITH_WIMAX
|
||||
else if (strcmp (*argv, "nsp") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1693,7 +1693,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1801,7 +1801,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
|||
id_specified = TRUE;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1903,7 +1903,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
|
|||
if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) {
|
||||
selector = *argv;
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -976,7 +976,7 @@ do_devices_list (NmCli *nmc, int argc, char **argv)
|
|||
iface_specified = TRUE;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1119,7 +1119,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
|
|||
iface_specified = TRUE;
|
||||
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1129,7 +1129,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
|
|||
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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1247,7 +1247,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1255,7 +1255,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
} else if (strcmp (*argv, "bssid") == 0 || strcmp (*argv, "hwaddr") == 0) {
|
||||
/* hwaddr is deprecated and will be removed later */
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1619,14 +1619,14 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
iface = *argv;
|
||||
} else if (strcmp (*argv, "bssid") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1640,14 +1640,14 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
} else if (strcmp (*argv, "password") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
password = *argv;
|
||||
} else if (strcmp (*argv, "wep-key-type") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1664,7 +1664,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
} else if (strcmp (*argv, "name") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1675,7 +1675,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
@ -1896,14 +1896,14 @@ do_device_wimax_list (NmCli *nmc, int argc, char **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);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
iface = *argv;
|
||||
} else if (strcmp (*argv, "nsp") == 0) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
|
||||
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -45,13 +45,15 @@ matches (const char *cmd, const char *pattern)
|
|||
int
|
||||
next_arg (int *argc, char ***argv)
|
||||
{
|
||||
if (*argc <= 1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
int arg_num = *argc;
|
||||
|
||||
if (arg_num > 0) {
|
||||
(*argc)--;
|
||||
(*argv)++;
|
||||
}
|
||||
if (arg_num <= 1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue