diff options
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/lib/command.c b/lib/command.c index 5cf1a4f57a..7be54907ed 100644 --- a/lib/command.c +++ b/lib/command.c @@ -889,6 +889,15 @@ enum node_type node_parent(enum node_type node) case PCEP_PCC_NODE: ret = PCEP_NODE; break; + case SRV6_NODE: + ret = SEGMENT_ROUTING_NODE; + break; + case SRV6_LOCS_NODE: + ret = SRV6_NODE; + break; + case SRV6_LOC_NODE: + ret = SRV6_LOCS_NODE; + break; default: ret = CONFIG_NODE; break; @@ -1049,6 +1058,7 @@ int cmd_execute_command(vector vline, struct vty *vty, return saved_ret; if (ret != CMD_SUCCESS && ret != CMD_WARNING + && ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE && ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED) { /* This assumes all nodes above CONFIG_NODE are childs of * CONFIG_NODE */ @@ -1062,6 +1072,7 @@ int cmd_execute_command(vector vline, struct vty *vty, ret = cmd_execute_command_real(vline, FILTER_RELAXED, vty, cmd, 0); if (ret == CMD_SUCCESS || ret == CMD_WARNING + || ret == CMD_ERR_AMBIGUOUS || ret == CMD_ERR_INCOMPLETE || ret == CMD_NOT_MY_INSTANCE || ret == CMD_WARNING_CONFIG_FAILED) return ret; @@ -1260,6 +1271,7 @@ int command_config_read_one_line(struct vty *vty, while (!(use_daemon && ret == CMD_SUCCESS_DAEMON) && !(!use_daemon && ret == CMD_ERR_NOTHING_TODO) && ret != CMD_SUCCESS && ret != CMD_WARNING + && ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE && ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED && ret != CMD_NO_LEVEL_UP) ret = cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd, @@ -1484,6 +1496,56 @@ static void permute(struct graph_node *start, struct vty *vty) 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 + 1]; + 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) { struct cmd_node *node = vector_slot(cmdvec, vty->node); @@ -1497,8 +1559,10 @@ int cmd_list_cmds(struct vty *vty, int do_permute) i++) if ((element = vector_slot(node->cmd_vector, i)) && element->attr != CMD_ATTR_DEPRECATED - && element->attr != CMD_ATTR_HIDDEN) - vty_out(vty, " %s\n", element->string); + && element->attr != CMD_ATTR_HIDDEN) { + vty_out(vty, " "); + print_cmd(vty, element->string); + } } return CMD_SUCCESS; } @@ -2231,11 +2295,7 @@ DEFUN (no_banner_motd, return CMD_SUCCESS; } -DEFUN(find, - find_cmd, - "find REGEX...", - "Find CLI command matching a regular expression\n" - "Search pattern (POSIX regex)\n") +int cmd_find_cmds(struct vty *vty, struct cmd_token **argv, int argc) { const struct cmd_node *node; const struct cmd_element *cli; @@ -2302,9 +2362,10 @@ DEFUN(find, for (unsigned int j = 0; j < vector_active(clis); j++) { cli = vector_slot(clis, j); - if (regexec(&exp, cli->string, 0, NULL, 0) == 0) - vty_out(vty, " (%s) %s\n", - node->name, cli->string); + if (regexec(&exp, cli->string, 0, NULL, 0) == 0) { + vty_out(vty, " (%s) ", node->name); + print_cmd(vty, cli->string); + } } } @@ -2313,6 +2374,15 @@ done: return CMD_SUCCESS; } +DEFUN(find, + find_cmd, + "find REGEX...", + "Find CLI command matching a regular expression\n" + "Search pattern (POSIX regex)\n") +{ + return cmd_find_cmds(vty, argv, argc); +} + #if defined(DEV_BUILD) && defined(HAVE_SCRIPTING) DEFUN(script, script_cmd, |
