diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-02-14 16:38:16 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-02-14 16:57:13 +0100 |
commit | d3ffe15f17daa65446b3b628a9f481f01dadd35d (patch) | |
tree | 24bc62dc9aab6657ed41e9589c6396efbc639eee | |
parent | cd03cbde4f8804ccc4a0446d92d462749cddb73b (diff) |
cli: add nmcli g logging completionlr/completion-4
This is sort of ugly, because it includes the domain and log levels
verbatim. They're just plain strings on the API, there's no way the
client would know which ones are valid.
On the other hand this kills one of two uses of nmc_parse_args(), which
probably means it's not a very good abstraction and maybe we should get
rid of it altogether. It is in particular unfriendly to argument
completion.
-rw-r--r-- | clients/cli/general.c | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/clients/cli/general.c b/clients/cli/general.c index 512ec2919..70a40f1ca 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -632,6 +632,23 @@ show_general_logging (NmCli *nmc) return TRUE; } +static void +nmc_complete_strings_nocase (const char *prefix, ...) +{ + va_list args; + const char *candidate; + int len; + + len = strlen (prefix); + + va_start (args, prefix); + while ((candidate = va_arg (args, const char *))) { + if (strncasecmp (prefix, candidate, len) == 0) + g_print ("%s\n", candidate); + } + va_end (args); +} + static NMCResultCode do_general_logging (NmCli *nmc, int argc, char **argv) { @@ -652,19 +669,45 @@ do_general_logging (NmCli *nmc, int argc, char **argv) /* arguments provided -> set logging level and domains */ const char *level = NULL; const char *domains = NULL; - nmc_arg_t exp_args[] = { {"level", TRUE, &level, TRUE}, - {"domains", TRUE, &domains, TRUE}, - {NULL} }; - /* TODO: nmc_parse_args needs completion */ + do { + if (argc == 1 && nmc->complete) + nmc_complete_strings (*argv, "level", "domains", NULL); + + if (matches (*argv, "level") == 0) { + if (next_arg (&argc, &argv) != 0) { + g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1)); + return NMC_RESULT_ERROR_USER_INPUT; + } + if (argc == 1 && nmc->complete) { + nmc_complete_strings_nocase (*argv, "TRACE", "DEBUG", "INFO", "WARN", + "ERR", "OFF", "KEEP", NULL); + } + level = *argv; + } else if (matches (*argv, "domains") == 0) { + if (next_arg (&argc, &argv) != 0) { + g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1)); + return NMC_RESULT_ERROR_USER_INPUT; + } + if (argc == 1 && nmc->complete) { + nmc_complete_strings_nocase (*argv, "PLATFORM", "RFKILL", "ETHER", "WIFI", "BT", + "MB", "DHCP4", "DHCP6", "PPP", "WIFI_SCAN", "IP4", + "IP6", "AUTOIP4", "DNS", "VPN", "SHARING", "SUPPLICANT", + "AGENTS", "SETTINGS", "SUSPEND", "CORE", "DEVICE", "OLPC", + "INFINIBAND", "FIREWALL", "ADSL", "BOND", "VLAN", "BRIDGE", + "DBUS_PROPS", "TEAM", "CONCHECK", "DCB", "DISPATCH", "AUDIT", + "SYSTEMD", "VPN_PLUGIN", "PROXY", NULL); + } + domains = *argv; + } else { + g_string_printf (nmc->return_text, _("Error: property '%s' is not known."), *argv); + return NMC_RESULT_ERROR_USER_INPUT; + } + } while (next_arg (&argc, &argv) == 0); + if (nmc->complete) return nmc->return_value; - if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, &error)) { - g_string_assign (nmc->return_text, error->message); - return error->code; - } - nm_client_set_logging (nmc->client, level, domains, &error); if (error) { g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"), |