main/test: Use ast_cli_completion_add.

Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b
This commit is contained in:
Corey Farrell
2018-03-17 03:16:24 -04:00
parent d5bfba60d2
commit 2c1ad2f510

View File

@@ -691,40 +691,40 @@ static struct ast_test *test_alloc(ast_test_cb_t *cb)
return test; return test;
} }
static char *complete_test_category(const char *line, const char *word, int pos, int state) static char *complete_test_category(const char *word)
{ {
int which = 0;
int wordlen = strlen(word); int wordlen = strlen(word);
char *ret = NULL;
struct ast_test *test; struct ast_test *test;
AST_LIST_LOCK(&tests); AST_LIST_LOCK(&tests);
AST_LIST_TRAVERSE(&tests, test, entry) { AST_LIST_TRAVERSE(&tests, test, entry) {
if (!strncasecmp(word, test->info.category, wordlen) && ++which > state) { if (!strncasecmp(word, test->info.category, wordlen)) {
ret = ast_strdup(test->info.category); if (ast_cli_completion_add(ast_strdup(test->info.category))) {
break; break;
}
} }
} }
AST_LIST_UNLOCK(&tests); AST_LIST_UNLOCK(&tests);
return ret;
return NULL;
} }
static char *complete_test_name(const char *line, const char *word, int pos, int state, const char *category) static char *complete_test_name(const char *word, const char *category)
{ {
int which = 0;
int wordlen = strlen(word); int wordlen = strlen(word);
char *ret = NULL;
struct ast_test *test; struct ast_test *test;
AST_LIST_LOCK(&tests); AST_LIST_LOCK(&tests);
AST_LIST_TRAVERSE(&tests, test, entry) { AST_LIST_TRAVERSE(&tests, test, entry) {
if (!test_cat_cmp(test->info.category, category) && (!strncasecmp(word, test->info.name, wordlen) && ++which > state)) { if (!test_cat_cmp(test->info.category, category) && !strncasecmp(word, test->info.name, wordlen)) {
ret = ast_strdup(test->info.name); if (ast_cli_completion_add(ast_strdup(test->info.name))) {
break; break;
}
} }
} }
AST_LIST_UNLOCK(&tests); AST_LIST_UNLOCK(&tests);
return ret;
return NULL;
} }
/* CLI commands */ /* CLI commands */
@@ -749,22 +749,22 @@ static char *test_cli_show_registered(struct ast_cli_entry *e, int cmd, struct a
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
if (a->pos == 3) { if (a->pos == 3) {
return ast_cli_complete(a->word, option1, a->n); return ast_cli_complete(a->word, option1, -1);
} }
if (a->pos == 4) { if (a->pos == 4 && !strcasecmp(a->argv[3], "category")) {
return complete_test_category(a->line, a->word, a->pos, a->n); return complete_test_category(a->word);
} }
if (a->pos == 5) { if (a->pos == 5) {
return ast_cli_complete(a->word, option2, a->n); return ast_cli_complete(a->word, option2, -1);
} }
if (a->pos == 6) { if (a->pos == 6) {
return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]); return complete_test_name(a->word, a->argv[4]);
} }
return NULL; return NULL;
case CLI_HANDLER: case CLI_HANDLER:
if ((a->argc < 4) || (a->argc == 6) || (a->argc > 7) || if ((a->argc < 4) || (a->argc == 6) || (a->argc > 7) ||
((a->argc == 4) && strcmp(a->argv[3], "all")) || ((a->argc == 4) && strcasecmp(a->argv[3], "all")) ||
((a->argc == 7) && strcmp(a->argv[5], "name"))) { ((a->argc == 7) && strcasecmp(a->argv[5], "name"))) {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
} }
ast_cli(a->fd, FORMAT, "Category", "Name", "Summary", "Test Result"); ast_cli(a->fd, FORMAT, "Category", "Name", "Summary", "Test Result");
@@ -808,16 +808,16 @@ static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struc
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
if (a->pos == 2) { if (a->pos == 2) {
return ast_cli_complete(a->word, option1, a->n); return ast_cli_complete(a->word, option1, -1);
} }
if (a->pos == 3) { if (a->pos == 3 && !strcasecmp(a->argv[2], "category")) {
return complete_test_category(a->line, a->word, a->pos, a->n); return complete_test_category(a->word);
} }
if (a->pos == 4) { if (a->pos == 4) {
return ast_cli_complete(a->word, option2, a->n); return ast_cli_complete(a->word, option2, -1);
} }
if (a->pos == 5) { if (a->pos == 5) {
return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]); return complete_test_name(a->word, a->argv[3]);
} }
return NULL; return NULL;
case CLI_HANDLER: case CLI_HANDLER:
@@ -826,7 +826,7 @@ static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struc
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
} }
if ((a->argc == 3) && !strcmp(a->argv[2], "all")) { /* run all registered tests */ if ((a->argc == 3) && !strcasecmp(a->argv[2], "all")) { /* run all registered tests */
ast_cli(a->fd, "Running all available tests...\n\n"); ast_cli(a->fd, "Running all available tests...\n\n");
test_execute_multiple(NULL, NULL, a); test_execute_multiple(NULL, NULL, a);
} else if (a->argc == 4) { /* run only tests within a category */ } else if (a->argc == 4) { /* run only tests within a category */
@@ -877,7 +877,7 @@ static char *test_cli_show_results(struct ast_cli_entry *e, int cmd, struct ast_
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
if (a->pos == 3) { if (a->pos == 3) {
return ast_cli_complete(a->word, option1, a->n); return ast_cli_complete(a->word, option1, -1);
} }
return NULL; return NULL;
case CLI_HANDLER: case CLI_HANDLER:
@@ -885,11 +885,11 @@ static char *test_cli_show_results(struct ast_cli_entry *e, int cmd, struct ast_
/* verify input */ /* verify input */
if (a->argc != 4) { if (a->argc != 4) {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
} else if (!strcmp(a->argv[3], "passed")) { } else if (!strcasecmp(a->argv[3], "passed")) {
mode = 2; mode = 2;
} else if (!strcmp(a->argv[3], "failed")) { } else if (!strcasecmp(a->argv[3], "failed")) {
mode = 1; mode = 1;
} else if (!strcmp(a->argv[3], "all")) { } else if (!strcasecmp(a->argv[3], "all")) {
mode = 0; mode = 0;
} else { } else {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
@@ -950,7 +950,7 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
if (a->pos == 3) { if (a->pos == 3) {
return ast_cli_complete(a->word, option, a->n); return ast_cli_complete(a->word, option, -1);
} }
return NULL; return NULL;
case CLI_HANDLER: case CLI_HANDLER:
@@ -958,10 +958,10 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct
/* verify input */ /* verify input */
if (a->argc < 4 || a->argc > 5) { if (a->argc < 4 || a->argc > 5) {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
} else if (!strcmp(a->argv[3], "xml")) { } else if (!strcasecmp(a->argv[3], "xml")) {
type = "xml"; type = "xml";
isxml = 1; isxml = 1;
} else if (!strcmp(a->argv[3], "txt")) { } else if (!strcasecmp(a->argv[3], "txt")) {
type = "txt"; type = "txt";
} else { } else {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;