diff options
author | Filip Pokryvka <fpokryvk@redhat.com> | 2024-03-18 10:42:10 +0100 |
---|---|---|
committer | Filip Pokryvka <fpokryvk@redhat.com> | 2024-03-18 13:42:54 +0100 |
commit | 444302e69db294c25dc594f83c3c1a4e33648757 (patch) | |
tree | b91e4da7971d17d199cdad9d6e7afe73f0b0d737 | |
parent | f9397a57408b4da2d29086ded4d0cfd75409049b (diff) |
nmcli: fix bash completion for fieldsfp/complete_args_fix2
The code handling options with supposes, that options
are split by `=`, which is not the case. This fixes the following:
```
nmcli -f ipv4.ad\t\t
nmcli -f ipv4.ad=ipv4.addresses
nmcli --field ipv4.ad\t\t
nmcli --field ipv4.ad=ipv4.addresses
```
Using options with values separated with `=` remains broken,
but this change doesn't affect it:
```
nmcli --field=ipv4.ad\t\t
nmcli --field=ipv4.ad
```
Also, `man` and `usage` uses `--color auto|yes|no`,
not `--color=auto|yes|no`. So, this fix should be sufficient.
Bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=2115827
-rw-r--r-- | src/nmcli/nmcli.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/nmcli/nmcli.c b/src/nmcli/nmcli.c index 6de42faa00..998dd12d4f 100644 --- a/src/nmcli/nmcli.c +++ b/src/nmcli/nmcli.c @@ -162,17 +162,18 @@ complete_one(gpointer key, gpointer value, gpointer user_data) last = prefix; if ((!*last && !strchr(name, '.')) || matches(last, name)) { - if (option != prefix) { + if (!nm_streq0(option, prefix)) { /* value prefix was not a standalone argument, * it was part of --option=<value> argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s\n", option); + } else { + nmc_print("%.*s%s%s\n", + (int) (last - prefix), + prefix, + name, + strcmp(last, name) == 0 ? "," : ""); } - nmc_print("%.*s%s%s\n", - (int) (last - prefix), - prefix, - name, - strcmp(last, name) == 0 ? "," : ""); } } @@ -224,13 +225,14 @@ complete_option_with_value(const char *option, const char *prefix, ...) va_start(args, prefix); while ((candidate = va_arg(args, const char *))) { if (!*prefix || matches(prefix, candidate)) { - if (option != prefix) { + if (!nm_streq0(option, prefix)) { /* value prefix was not a standalone argument, * it was part of --option=<value> argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s%s\n", option, candidate + strlen(prefix)); + } else { + nmc_print("%s\n", candidate); } - nmc_print("%s\n", candidate); } } va_end(args); |