summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2018-03-16 10:34:16 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2018-03-16 10:34:16 -0500
commita33af7243cca3dfb465753ad6df7e6b037d37f81 (patch)
tree926c1049716a77e0d7f187537f972d8d273d4e6d
parentdbf5ff6ed06bf32993fc9b08fc1f0d86f2281826 (diff)
parentb45bb476bb985909d7d891ceb1a9cccfb7763ec6 (diff)
Merge "cli: Enable ast_cli_completion_add on public completion generators."
-rw-r--r--main/cli.c24
-rw-r--r--main/pbx_app.c27
2 files changed, 34 insertions, 17 deletions
diff --git a/main/cli.c b/main/cli.c
index 80c184328..e46d3427c 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1655,8 +1655,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;
}
@@ -1682,9 +1689,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);
diff --git a/main/pbx_app.c b/main/pbx_app.c
index ec6bc7589..df8126c7f 100644
--- a/main/pbx_app.c
+++ b/main/pbx_app.c
@@ -275,7 +275,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) {
@@ -437,20 +437,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);