mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 07:03:07 +00:00
lib: fix output of "list" and "find" commands
Currently, we output the command exactly how it is defined in DEFUN. We shouldn't output varnames and excessive whitespace. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
parent
c22789620d
commit
5b96d81c86
@ -1484,6 +1484,56 @@ static void permute(struct graph_node *start, struct vty *vty)
|
|||||||
list_delete_node(position, listtail(position));
|
list_delete_node(position, listtail(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_cmd(struct vty *vty, const char *cmd)
|
||||||
|
{
|
||||||
|
int i, j, len = strlen(cmd);
|
||||||
|
char buf[len];
|
||||||
|
bool skip = false;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
/* skip varname */
|
||||||
|
if (cmd[i] == '$')
|
||||||
|
skip = true;
|
||||||
|
else if (strchr(" ()<>[]{}|", cmd[i]))
|
||||||
|
skip = false;
|
||||||
|
|
||||||
|
if (skip)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (isspace(cmd[i])) {
|
||||||
|
/* skip leading whitespace */
|
||||||
|
if (i == 0)
|
||||||
|
continue;
|
||||||
|
/* skip trailing whitespace */
|
||||||
|
if (i == len - 1)
|
||||||
|
continue;
|
||||||
|
/* skip all whitespace after opening brackets or pipe */
|
||||||
|
if (strchr("(<[{|", cmd[i - 1])) {
|
||||||
|
while (isspace(cmd[i + 1]))
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* skip repeated whitespace */
|
||||||
|
if (isspace(cmd[i + 1]))
|
||||||
|
continue;
|
||||||
|
/* skip whitespace before closing brackets or pipe */
|
||||||
|
if (strchr(")>]}|", cmd[i + 1]))
|
||||||
|
continue;
|
||||||
|
/* convert tabs to spaces */
|
||||||
|
if (cmd[i] == '\t') {
|
||||||
|
buf[j++] = ' ';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[j++] = cmd[i];
|
||||||
|
}
|
||||||
|
buf[j] = 0;
|
||||||
|
|
||||||
|
vty_out(vty, "%s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_list_cmds(struct vty *vty, int do_permute)
|
int cmd_list_cmds(struct vty *vty, int do_permute)
|
||||||
{
|
{
|
||||||
struct cmd_node *node = vector_slot(cmdvec, vty->node);
|
struct cmd_node *node = vector_slot(cmdvec, vty->node);
|
||||||
@ -1497,8 +1547,10 @@ int cmd_list_cmds(struct vty *vty, int do_permute)
|
|||||||
i++)
|
i++)
|
||||||
if ((element = vector_slot(node->cmd_vector, i))
|
if ((element = vector_slot(node->cmd_vector, i))
|
||||||
&& element->attr != CMD_ATTR_DEPRECATED
|
&& element->attr != CMD_ATTR_DEPRECATED
|
||||||
&& element->attr != CMD_ATTR_HIDDEN)
|
&& element->attr != CMD_ATTR_HIDDEN) {
|
||||||
vty_out(vty, " %s\n", element->string);
|
vty_out(vty, " ");
|
||||||
|
print_cmd(vty, element->string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -2298,9 +2350,10 @@ int cmd_find_cmds(struct vty *vty, struct cmd_token **argv, int argc)
|
|||||||
for (unsigned int j = 0; j < vector_active(clis); j++) {
|
for (unsigned int j = 0; j < vector_active(clis); j++) {
|
||||||
cli = vector_slot(clis, j);
|
cli = vector_slot(clis, j);
|
||||||
|
|
||||||
if (regexec(&exp, cli->string, 0, NULL, 0) == 0)
|
if (regexec(&exp, cli->string, 0, NULL, 0) == 0) {
|
||||||
vty_out(vty, " (%s) %s\n",
|
vty_out(vty, " (%s) ", node->name);
|
||||||
node->name, cli->string);
|
print_cmd(vty, cli->string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user