]> git.puffer.fish Git - mirror/frr.git/commitdiff
Fix optional arguments with description interactions
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 26 Aug 2015 16:01:31 +0000 (09:01 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 26 Aug 2015 16:01:31 +0000 (09:01 -0700)
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
<cr>
tor-22(config-router)# neighbor swp1 interface v6only

This behavior is now consistent with non-optional last
arguments.

lib/command.c

index d487ce4e73a47478ffe96e6b55a996a797a659ee..e7027fca26af2e15143a843786d261ff4d24a063 100644 (file)
@@ -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);