summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-05-10 16:38:48 +0200
committerQuentin Young <qlyoung@users.noreply.github.com>2017-05-15 10:27:43 -0400
commit7f059ea614bf310015bcb4e9b8dd7b1f6c6e072a (patch)
tree6fdc433e5c6d8877380874935130f950fa15db3b /lib/command.c
parent70d44c5cd4f28f9d08a24f519d859885d92e2a13 (diff)
vtysh: autocomplete variables
This asks the connected daemons for their variable completions through a hidden CLI command. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/command.c b/lib/command.c
index 5b4c63fa95..cc597952e4 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -727,6 +727,38 @@ cmd_variable_handler_register (const struct cmd_variable_handler *cvh)
listnode_add(varhandlers, (void *)cvh);
}
+DEFUN_HIDDEN (autocomplete,
+ autocomplete_cmd,
+ "autocomplete TYPE TEXT VARNAME",
+ "Autocompletion handler (internal, for vtysh)\n"
+ "cmd_token->type\n"
+ "cmd_token->text\n"
+ "cmd_token->varname\n")
+{
+ struct cmd_token tok;
+ vector comps = vector_init(32);
+ size_t i;
+
+ memset(&tok, 0, sizeof(tok));
+ tok.type = atoi(argv[1]->arg);
+ tok.text = argv[2]->arg;
+ tok.varname = argv[3]->arg;
+ if (!strcmp(tok.varname, "-"))
+ tok.varname = NULL;
+
+ cmd_variable_complete(&tok, NULL, comps);
+
+ for (i = 0; i < vector_active(comps); i++)
+ {
+ char *text = vector_slot(comps, i);
+ vty_out(vty, "%s\n", text);
+ XFREE(MTYPE_COMPLETION, text);
+ }
+
+ vector_free(comps);
+ return CMD_SUCCESS;
+}
+
/**
* Generate possible tab-completions for the given input. This function only
* returns results that would result in a valid command if used as Readline
@@ -2434,6 +2466,8 @@ install_default (enum node_type node)
install_element (node, &config_write_cmd);
install_element (node, &show_running_config_cmd);
+
+ install_element (node, &autocomplete_cmd);
}
/* Initialize command interface. Install basic nodes and commands.
@@ -2483,6 +2517,7 @@ cmd_init (int terminal)
install_element (VIEW_NODE, &show_logging_cmd);
install_element (VIEW_NODE, &show_commandtree_cmd);
install_element (VIEW_NODE, &echo_cmd);
+ install_element (VIEW_NODE, &autocomplete_cmd);
}
if (terminal)