lib, vtysh: add find COMMAND

Substring search through all defined commands in all nodes.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2017-07-25 14:20:55 -04:00
parent a83a533139
commit cf6c83e712
No known key found for this signature in database
GPG Key ID: DAF48E0F57E0834F
3 changed files with 46 additions and 48 deletions

View File

@ -42,7 +42,6 @@
#include "command_graph.h"
#include "qobj.h"
#include "defaults.h"
#include "termtable.h"
DEFINE_MTYPE(LIB, HOST, "Host config")
DEFINE_MTYPE(LIB, STRVEC, "String vector")
@ -2431,16 +2430,19 @@ DEFUN(find,
"Text to search for\n")
{
char *text = argv_concat(argv, argc, 1);
const struct cmd_node *node;
const struct cmd_element *cli;
vector clis;
for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
struct cmd_node *node = vector_slot(cmdvec, i);
node = vector_slot(cmdvec, i);
if (!node)
continue;
vector clis = node->cmd_vector;
clis = node->cmd_vector;
for (unsigned int j = 0; j < vector_active(clis); j++) {
struct cmd_element *cli = vector_slot(clis, j);
cli = vector_slot(clis, j);
if (strcasestr(cli->string, text))
vty_out(vty, "(%s) %s",
vty_out(vty, " (%s) %s\n",
node_names[node->node], cli->string);
}
}

View File

@ -68,7 +68,7 @@ struct host {
char *motdfile;
};
/* List of CLI nodes. Please remember to update the names array below. */
/* List of CLI nodes. Please remember to update the name array in command.c. */
enum node_type {
AUTH_NODE, /* Authentication mode of vty interface. */
VIEW_NODE, /* View node. Default mode of vty interface. */
@ -138,6 +138,7 @@ enum node_type {
NODE_TYPE_MAX, /* maximum */
};
extern vector cmdvec;
extern const char *node_names[];
/* Node which has some commands and prompt string and configuration

View File

@ -2582,9 +2582,39 @@ DEFUN (config_list,
return cmd_list_cmds(vty, argc == 2);
}
DEFUN(find,
find_cmd,
"find COMMAND...",
"Find CLI command containing text\n"
"Text to search for\n")
{
char *text = argv_concat(argv, argc, 1);
const struct cmd_node *node;
const struct cmd_element *cli;
vector clis;
for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
node = vector_slot(cmdvec, i);
if (!node)
continue;
clis = node->cmd_vector;
for (unsigned int j = 0; j < vector_active(clis); j++) {
cli = vector_slot(clis, j);
if (strcasestr(cli->string, text))
fprintf(stdout, " (%s) %s\n",
node_names[node->node], cli->string);
}
}
XFREE(MTYPE_TMP, text);
return CMD_SUCCESS;
}
static void vtysh_install_default(enum node_type node)
{
install_element(node, &config_list_cmd);
install_element(node, &find_cmd);
}
/* Making connection to protocol daemon. */
@ -2876,48 +2906,13 @@ void vtysh_init_vty(void)
install_node(&isis_node, NULL);
install_node(&vty_node, NULL);
vtysh_install_default(VIEW_NODE);
vtysh_install_default(CONFIG_NODE);
vtysh_install_default(BGP_NODE);
vtysh_install_default(RIP_NODE);
vtysh_install_default(INTERFACE_NODE);
vtysh_install_default(LINK_PARAMS_NODE);
vtysh_install_default(NS_NODE);
vtysh_install_default(VRF_NODE);
vtysh_install_default(RMAP_NODE);
vtysh_install_default(ZEBRA_NODE);
vtysh_install_default(BGP_VPNV4_NODE);
vtysh_install_default(BGP_VPNV6_NODE);
vtysh_install_default(BGP_IPV4_NODE);
vtysh_install_default(BGP_IPV4M_NODE);
vtysh_install_default(BGP_IPV4L_NODE);
vtysh_install_default(BGP_IPV6_NODE);
vtysh_install_default(BGP_IPV6M_NODE);
vtysh_install_default(BGP_EVPN_NODE);
vtysh_install_default(BGP_EVPN_VNI_NODE);
vtysh_install_default(BGP_IPV6L_NODE);
#if ENABLE_BGP_VNC
vtysh_install_default(BGP_VRF_POLICY_NODE);
vtysh_install_default(BGP_VNC_DEFAULTS_NODE);
vtysh_install_default(BGP_VNC_NVE_GROUP_NODE);
vtysh_install_default(BGP_VNC_L2_GROUP_NODE);
#endif
vtysh_install_default(OSPF_NODE);
vtysh_install_default(EIGRP_NODE);
vtysh_install_default(BABEL_NODE);
vtysh_install_default(RIPNG_NODE);
vtysh_install_default(OSPF6_NODE);
vtysh_install_default(LDP_NODE);
vtysh_install_default(LDP_IPV4_NODE);
vtysh_install_default(LDP_IPV6_NODE);
vtysh_install_default(LDP_IPV4_IFACE_NODE);
vtysh_install_default(LDP_IPV6_IFACE_NODE);
vtysh_install_default(LDP_L2VPN_NODE);
vtysh_install_default(LDP_PSEUDOWIRE_NODE);
vtysh_install_default(ISIS_NODE);
vtysh_install_default(KEYCHAIN_NODE);
vtysh_install_default(KEYCHAIN_KEY_NODE);
vtysh_install_default(VTY_NODE);
struct cmd_node *node;
for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
node = vector_slot(cmdvec, i);
if (!node || node->node == VIEW_NODE)
continue;
vtysh_install_default(node->node);
}
install_element(VIEW_NODE, &vtysh_enable_cmd);
install_element(ENABLE_NODE, &vtysh_config_terminal_cmd);