summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-02-25 14:26:20 +0100
committerLubomir Rintel <lkundrak@v3.sk>2018-06-13 14:44:18 +0200
commite6abc96e133e238831634d925f6fd7c993729f24 (patch)
treecf01aab2fd76813b45f56ff08ea9be6761f170a3
parentc00e17578f727b34c41ad54c8348a49f894969c2 (diff)
downloadNetworkManager-e6abc96e133e238831634d925f6fd7c993729f24.tar.gz
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.
-rw-r--r--clients/cli/utils.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index 9cc01c7240..7d687c2c29 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -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++;
}