From 16cf945a5066f56237a15828c99ded4f42266f0a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 26 Aug 2015 09:01:31 -0700 Subject: [PATCH] Fix optional arguments with description interactions Ticket: CM-6659 Reviewed by: CCR-3203 Testing: See bug If you have a cli like this: "neighbor WORD interface {v6only}" When in the cli you hit ? after entering v6only you get this: tor-11(config-router)# neighbor swp1 interface v6only % There is no matched command. tor-11(config-router)# neighbor swp1 interface v6only With this fix we now see: tor-22(config-router)# neighbor swp1 interface v6only tor-22(config-router)# neighbor swp1 interface v6only This behavior is now consistent with non-optional last arguments. --- lib/command.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/command.c b/lib/command.c index d487ce4e73..e7027fca26 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2102,6 +2102,8 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) char *command; vector matches = NULL; vector match_vector; + uint32_t command_found = 0; + const char *last_word; /* Set index. */ if (vector_active (vline) == 0) @@ -2187,13 +2189,13 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) } /* Make description vector. */ - for (i = 0; i < vector_active (matches); i++) + for (i = 0; i < vector_active (matches); i++) { if ((cmd_element = vector_slot (cmd_vector, i)) != NULL) { unsigned int j; - const char *last_word; vector vline_trimmed; + command_found++; last_word = vector_slot(vline, vector_active(vline) - 1); if (last_word == NULL || !strlen(last_word)) { @@ -2222,6 +2224,18 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) vector_set(matchvec, token); } } + } + + /* + * We can get into this situation when the command is complete + * but the last part of the command is an optional piece of + * cli. + */ + last_word = vector_slot(vline, vector_active(vline) - 1); + if (command_found == 0 && (last_word == NULL || !strlen(last_word))) { + vector_set(matchvec, &token_cr); + } + vector_free (cmd_vector); cmd_matches_free(&matches); -- 2.39.5