mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-03 21:58:44 +02:00
cli/utils: make next_arg() recognize arguments that are not in "--option" form
This is going to make it possible to parse and complete argument lists in one go:
-nmc_complete_strings (*argv, "ifname", "bssid", NULL);
-next_arg (nmc, &argc, &argv, NULL);
-if (strcmp (*argv, "ifname") == 0)
-...
-else if (strcmp (*argv, "bssid") == 0)
-...
+option = next_arg (nmc, &argc, &argv, "ifname", "bssid", NULL)
+switch (option) {
+case 1:
+...
+case 2:
+...
Beautiful.
This commit is contained in:
parent
c00e17578f
commit
e6abc96e13
1 changed files with 12 additions and 4 deletions
|
|
@ -199,10 +199,18 @@ next_arg (NmCli *nmc, int *argc, char ***argv, ...)
|
|||
|
||||
/* Check command dependent options first */
|
||||
while ((cmd_option = va_arg (args, const char *))) {
|
||||
/* strip heading "--" form cmd_option */
|
||||
if (nmc_arg_is_option (**argv, cmd_option + 2)) {
|
||||
va_end (args);
|
||||
return cmd_option_pos;
|
||||
if (cmd_option[0] == '-' && cmd_option[1] == '-') {
|
||||
/* Match as an option (leading "--" stripped) */
|
||||
if (nmc_arg_is_option (**argv, cmd_option + 2)) {
|
||||
va_end (args);
|
||||
return cmd_option_pos;
|
||||
}
|
||||
} else {
|
||||
/* Match literally. */
|
||||
if (strcmp (**argv, cmd_option) == 0) {
|
||||
va_end (args);
|
||||
return cmd_option_pos;
|
||||
}
|
||||
}
|
||||
cmd_option_pos++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue