diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-19 11:57:08 +0100 |
|---|---|---|
| committer | Quentin Young <qlyoung@users.noreply.github.com> | 2017-05-15 10:27:43 -0400 |
| commit | 70d44c5cd4f28f9d08a24f519d859885d92e2a13 (patch) | |
| tree | c67e6c907a31487ca96b27e53a1f571c26f31bf9 /lib/vty.c | |
| parent | c09c46ae3c2702b3553e558f723e6de4fea3e05d (diff) | |
lib: cli: autocomplete variables
Shows known values in the appropriate naming domain when the user hits
<?> or <Tab>. This patch only works in the telnet CLI, the next patch
adds vtysh support.
Included completions:
- interface names
- route-map names
- prefix-list names
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/vty.c')
| -rw-r--r-- | lib/vty.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -955,14 +955,14 @@ vty_complete_command (struct vty *vty) vty_backward_pure_word (vty); vty_insert_word_overwrite (vty, matched[0]); vty_self_insert (vty, ' '); - XFREE (MTYPE_TMP, matched[0]); + XFREE (MTYPE_COMPLETION, matched[0]); break; case CMD_COMPLETE_MATCH: vty_prompt (vty); vty_redraw_line (vty); vty_backward_pure_word (vty); vty_insert_word_overwrite (vty, matched[0]); - XFREE (MTYPE_TMP, matched[0]); + XFREE (MTYPE_COMPLETION, matched[0]); break; case CMD_COMPLETE_LIST_MATCH: for (i = 0; matched[i] != NULL; i++) @@ -970,7 +970,7 @@ vty_complete_command (struct vty *vty) if (i != 0 && ((i % 6) == 0)) vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "%-10s ", matched[i]); - XFREE (MTYPE_TMP, matched[i]); + XFREE (MTYPE_COMPLETION, matched[i]); } vty_out (vty, "%s", VTY_NEWLINE); @@ -1109,6 +1109,26 @@ vty_describe_command (struct vty *vty) else vty_describe_fold (vty, width, desc_width, token); + if (IS_VARYING_TOKEN(token->type)) + { + const char *ref = vector_slot(vline, vector_active(vline) - 1); + + vector varcomps = vector_init (VECTOR_MIN_SIZE); + cmd_variable_complete (token, ref, varcomps); + + if (vector_active(varcomps) > 0) + { + vty_out(vty, " "); + for (size_t j = 0; j < vector_active (varcomps); j++) + { + char *item = vector_slot (varcomps, j); + vty_out(vty, " %s", item); + XFREE(MTYPE_COMPLETION, item); + } + vty_out(vty, "%s", VTY_NEWLINE); + } + vector_free(varcomps); + } #if 0 vty_out (vty, " %-*s %s%s", width desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd, |
