diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-02-14 15:57:08 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-02-14 16:57:13 +0100 |
commit | cd03cbde4f8804ccc4a0446d92d462749cddb73b (patch) | |
tree | 959f4f0c15e9e9409f4d9257b9f6f94e33bc2258 | |
parent | 90380924b53472ff951a7def6edf92cefb60b14a (diff) | |
download | NetworkManager-cd03cbde4f8804ccc4a0446d92d462749cddb73b.tar.gz |
cli: add completion for "nmcli c edit"
-rw-r--r-- | clients/cli/connections.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index f1d374839d..fc9668f21e 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -7876,6 +7876,18 @@ editor_init_existing_connection (NMConnection *connection) nmc_setting_connection_connect_handlers (s_con, connection); } +static void +nmc_complete_connection_type (const char *prefix, const NameItem *types) +{ + while (types->name) { + if (!*prefix || matches (prefix, types->name) == 0) + g_print ("%s\n", types->name); + if (types->alias && (!*prefix || matches (prefix, types->alias) == 0)) + g_print ("%s\n", types->alias); + types++; + } +} + static NMCResultCode do_connection_edit (NmCli *nmc, int argc, char **argv) { @@ -7903,9 +7915,8 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) {"path", TRUE, &con_path, FALSE}, {NULL} }; - /* TODO: complete uuid, path or id */ - if (nmc->complete) - return nmc->return_value; + if (argc == 1 && nmc->complete) + nmc_complete_strings (*argv, "type", "con-name", "id", "uuid", "path", NULL); nmc->return_value = NMC_RESULT_SUCCESS; @@ -7952,7 +7963,10 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) /* Existing connection */ NMConnection *found_con; - found_con = nmc_find_connection (connections, selector, con, NULL, FALSE); + found_con = nmc_find_connection (connections, selector, con, NULL, nmc->complete); + if (nmc->complete) + goto error; + if (!found_con) { g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con); nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; @@ -7984,6 +7998,12 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) editor_init_existing_connection (connection); } else { /* New connection */ + if (nmc->complete) { + if (type && argc == 0) + nmc_complete_connection_type (type, nmc_valid_connection_types); + goto error; + } + connection_type = check_valid_name (type, nmc_valid_connection_types, NULL, &err1); tmp_str = get_valid_options_string (nmc_valid_connection_types, NULL); |