]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
cli: Enable ast_cli_completion_add on public completion generators.
authorCorey Farrell <git@cfware.com>
Wed, 14 Mar 2018 17:38:01 +0000 (13:38 -0400)
committerCorey Farrell <git@cfware.com>
Thu, 15 Mar 2018 11:27:41 +0000 (05:27 -0600)
* ast_cli_complete
* ast_complete_channels
* ast_complete_applications

These generators will now use ast_cli_completion_add if state == -1.

Change-Id: I7ff311f0873099be0e43a3dc5415c0cd06d15756

main/cli.c
main/pbx_app.c

index fe20c340138f3d9653f00ed16a0c4068a8290341..dc75acb1288872d53e32fb861e85c89fbde7fd33 100644 (file)
@@ -1663,8 +1663,15 @@ char *ast_cli_complete(const char *word, const char * const choices[], int state
        len = ast_strlen_zero(word) ? 0 : strlen(word);
 
        for (i = 0; choices[i]; i++) {
-               if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
-                       return ast_strdup(choices[i]);
+               if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state) {
+                       if (state != -1) {
+                               return ast_strdup(choices[i]);
+                       }
+
+                       if (ast_cli_completion_add(ast_strdup(choices[i]))) {
+                               return NULL;
+                       }
+               }
        }
        return NULL;
 }
@@ -1690,9 +1697,16 @@ char *ast_complete_channels(const char *line, const char *word, int pos, int sta
                struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
 
                if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
-                       ret = ast_strdup(snapshot->name);
-                       ao2_ref(msg, -1);
-                       break;
+                       if (state != -1) {
+                               ret = ast_strdup(snapshot->name);
+                               ao2_ref(msg, -1);
+                               break;
+                       }
+
+                       if (ast_cli_completion_add(ast_strdup(snapshot->name))) {
+                               ao2_ref(msg, -1);
+                               break;
+                       }
                }
        }
        ao2_iterator_destroy(&iter);
index 1ce77122c5ff8baf5d48041271e18bbf55f99ac9..6ddb955c59b9786bfd3ebf5525376b5b2856bc62 100644 (file)
@@ -277,7 +277,7 @@ static char *handle_show_application(struct ast_cli_entry *e, int cmd, struct as
                 * application at one time. You can type 'show application Dial Echo' and
                 * you will see informations about these two applications ...
                 */
-               return ast_complete_applications(a->line, a->word, a->n);
+               return ast_complete_applications(a->line, a->word, -1);
        }
 
        if (a->argc < 4) {
@@ -439,20 +439,23 @@ char *ast_complete_applications(const char *line, const char *word, int state)
        AST_RWLIST_RDLOCK(&apps);
        AST_RWLIST_TRAVERSE(&apps, app, list) {
                cmp = strncasecmp(word, app->name, wordlen);
-               if (cmp > 0) {
-                       continue;
-               }
-               if (!cmp) {
+               if (cmp < 0) {
+                       /* No more matches. */
+                       break;
+               } else if (!cmp) {
                        /* Found match. */
-                       if (++which <= state) {
-                               /* Not enough matches. */
-                               continue;
+                       if (state != -1) {
+                               if (++which <= state) {
+                                       /* Not enough matches. */
+                                       continue;
+                               }
+                               ret = ast_strdup(app->name);
+                               break;
+                       }
+                       if (ast_cli_completion_add(ast_strdup(app->name))) {
+                               break;
                        }
-                       ret = ast_strdup(app->name);
-                       break;
                }
-               /* Not in container. */
-               break;
        }
        AST_RWLIST_UNLOCK(&apps);