mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 19:28:53 +00:00
cli: Enable ast_cli_completion_add on public completion generators.
* ast_cli_complete * ast_complete_channels * ast_complete_applications These generators will now use ast_cli_completion_add if state == -1. Change-Id: I7ff311f0873099be0e43a3dc5415c0cd06d15756
This commit is contained in:
24
main/cli.c
24
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);
|
len = ast_strlen_zero(word) ? 0 : strlen(word);
|
||||||
|
|
||||||
for (i = 0; choices[i]; i++) {
|
for (i = 0; choices[i]; i++) {
|
||||||
if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
|
if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state) {
|
||||||
return ast_strdup(choices[i]);
|
if (state != -1) {
|
||||||
|
return ast_strdup(choices[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_cli_completion_add(ast_strdup(choices[i]))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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);
|
struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
|
||||||
|
|
||||||
if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
|
if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
|
||||||
ret = ast_strdup(snapshot->name);
|
if (state != -1) {
|
||||||
ao2_ref(msg, -1);
|
ret = ast_strdup(snapshot->name);
|
||||||
break;
|
ao2_ref(msg, -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_cli_completion_add(ast_strdup(snapshot->name))) {
|
||||||
|
ao2_ref(msg, -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ao2_iterator_destroy(&iter);
|
ao2_iterator_destroy(&iter);
|
||||||
|
@@ -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
|
* application at one time. You can type 'show application Dial Echo' and
|
||||||
* you will see informations about these two applications ...
|
* 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) {
|
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_RDLOCK(&apps);
|
||||||
AST_RWLIST_TRAVERSE(&apps, app, list) {
|
AST_RWLIST_TRAVERSE(&apps, app, list) {
|
||||||
cmp = strncasecmp(word, app->name, wordlen);
|
cmp = strncasecmp(word, app->name, wordlen);
|
||||||
if (cmp > 0) {
|
if (cmp < 0) {
|
||||||
continue;
|
/* No more matches. */
|
||||||
}
|
|
||||||
if (!cmp) {
|
|
||||||
/* Found match. */
|
|
||||||
if (++which <= state) {
|
|
||||||
/* Not enough matches. */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ret = ast_strdup(app->name);
|
|
||||||
break;
|
break;
|
||||||
|
} else if (!cmp) {
|
||||||
|
/* Found match. */
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Not in container. */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
AST_RWLIST_UNLOCK(&apps);
|
AST_RWLIST_UNLOCK(&apps);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user