summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2016-07-11 22:38:16 +0200
committerLubomir Rintel <lkundrak@v3.sk>2016-08-01 13:52:36 +0200
commit9e8a227813281331e5831b502a7c149dcc0e9fb6 (patch)
tree1d7848611f23cbc8efece774b61e038576cb0c42
parenta410e40655a02bcc60ba1f400e331a3603c3d1b4 (diff)
downloadNetworkManager-9e8a227813281331e5831b502a7c149dcc0e9fb6.tar.gz
cli/connections: add completion to show subcommand
-rw-r--r--clients/cli/connections.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 5637581d69..9e284c8955 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -1745,32 +1745,34 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
GArray *order = NULL;
int i;
- /* Not (yet?) supported */
- if (nmc->complete)
- goto finish;
-
/* check connection show options [--active] [--show-secrets] */
for (i = 0; i < 3; i++) {
+ if (argc == 1 && nmc->complete) {
+ nmc_complete_strings (*argv, "--active", "--show-secrets",
+ "--order", NULL);
+ }
+
if (!active_only && nmc_arg_is_option (*argv, "active")) {
active_only = TRUE;
next_arg (&argc, &argv);
- }
- /* --show-secrets is deprecated in favour of global --show-secrets */
- /* Keep it here for backwards compatibility */
- if (!show_secrets && nmc_arg_is_option (*argv, "show-secrets")) {
+ } else if (!show_secrets && nmc_arg_is_option (*argv, "show-secrets")) {
+ /* --show-secrets is deprecated in favour of global --show-secrets */
+ /* Keep it here for backwards compatibility */
show_secrets = TRUE;
next_arg (&argc, &argv);
- }
- if (!order && nmc_arg_is_option (*argv, "order")) {
+ } else if (!order && nmc_arg_is_option (*argv, "order")) {
if (next_arg (&argc, &argv) != 0) {
g_set_error_literal (&err, NMCLI_ERROR, 0,
_("'--order' argument is missing"));
goto finish;
}
+ /* TODO: complete --order */
order = parse_preferred_connection_order (*argv, &err);
if (err)
goto finish;
next_arg (&argc, &argv);
+ } else {
+ break;
}
}
show_secrets = nmc->show_secrets || show_secrets;
@@ -1782,6 +1784,9 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
+ if (nmc->complete)
+ goto finish;
+
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
fields_str = fields_common;
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
@@ -1840,6 +1845,9 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
NMActiveConnection *acon = NULL;
const char *selector = NULL;
+ if (argc == 1 && nmc->complete)
+ nmc_complete_strings (*argv, "id", "uuid", "path", "apath", NULL);
+
if ( strcmp (*argv, "id") == 0
|| strcmp (*argv, "uuid") == 0
|| strcmp (*argv, "path") == 0
@@ -1852,10 +1860,13 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
}
}
- /* Find connection by id, uuid, path or apath */
- con = nmc_find_connection (nmc->connections, selector, *argv, &pos, FALSE);
- if (!con) {
- acon = find_active_connection (active_cons, nmc->connections, selector, *argv, NULL, FALSE);
+ /* Try to find connection by id, uuid or path first */
+ con = nmc_find_connection (nmc->connections, selector, *argv, &pos,
+ argc == 1 && nmc->complete);
+ if (!con && (!selector || strcmp (selector, "apath") == 0)) {
+ /* Try apath too */
+ acon = find_active_connection (active_cons, nmc->connections, "apath", *argv, NULL,
+ argc == 1 && nmc->complete);
if (acon)
con = NM_CONNECTION (nm_active_connection_get_connection (acon));
}
@@ -1880,6 +1891,11 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
continue;
}
+ if (nmc->complete) {
+ next_arg (&argc, &argv);
+ continue;
+ }
+
/* Show an empty line between connections */
if (new_line)
g_print ("\n");