From 2c1ad2f510678f43881db44c8b54f96620d05c4b Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sat, 17 Mar 2018 03:16:24 -0400 Subject: main/test: Use ast_cli_completion_add. Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b --- main/test.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/main/test.c b/main/test.c index f45ad9b62..b117c0814 100644 --- a/main/test.c +++ b/main/test.c @@ -691,40 +691,40 @@ static struct ast_test *test_alloc(ast_test_cb_t *cb) 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); - char *ret = NULL; struct ast_test *test; AST_LIST_LOCK(&tests); AST_LIST_TRAVERSE(&tests, test, entry) { - if (!strncasecmp(word, test->info.category, wordlen) && ++which > state) { - ret = ast_strdup(test->info.category); - break; + if (!strncasecmp(word, test->info.category, wordlen)) { + if (ast_cli_completion_add(ast_strdup(test->info.category))) { + break; + } } } 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); - char *ret = NULL; struct ast_test *test; AST_LIST_LOCK(&tests); AST_LIST_TRAVERSE(&tests, test, entry) { - if (!test_cat_cmp(test->info.category, category) && (!strncasecmp(word, test->info.name, wordlen) && ++which > state)) { - ret = ast_strdup(test->info.name); - break; + if (!test_cat_cmp(test->info.category, category) && !strncasecmp(word, test->info.name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(test->info.name))) { + break; + } } } AST_LIST_UNLOCK(&tests); - return ret; + + return NULL; } /* CLI commands */ @@ -749,22 +749,22 @@ static char *test_cli_show_registered(struct ast_cli_entry *e, int cmd, struct a return NULL; case CLI_GENERATE: 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) { - return complete_test_category(a->line, a->word, a->pos, a->n); + if (a->pos == 4 && !strcasecmp(a->argv[3], "category")) { + return complete_test_category(a->word); } 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) { - 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; case CLI_HANDLER: if ((a->argc < 4) || (a->argc == 6) || (a->argc > 7) || - ((a->argc == 4) && strcmp(a->argv[3], "all")) || - ((a->argc == 7) && strcmp(a->argv[5], "name"))) { + ((a->argc == 4) && strcasecmp(a->argv[3], "all")) || + ((a->argc == 7) && strcasecmp(a->argv[5], "name"))) { return CLI_SHOWUSAGE; } 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; case CLI_GENERATE: 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) { - return complete_test_category(a->line, a->word, a->pos, a->n); + if (a->pos == 3 && !strcasecmp(a->argv[2], "category")) { + return complete_test_category(a->word); } 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) { - 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; case CLI_HANDLER: @@ -826,7 +826,7 @@ static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struc 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"); test_execute_multiple(NULL, NULL, a); } 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; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option1, a->n); + return ast_cli_complete(a->word, option1, -1); } return NULL; case CLI_HANDLER: @@ -885,11 +885,11 @@ static char *test_cli_show_results(struct ast_cli_entry *e, int cmd, struct ast_ /* verify input */ if (a->argc != 4) { return CLI_SHOWUSAGE; - } else if (!strcmp(a->argv[3], "passed")) { + } else if (!strcasecmp(a->argv[3], "passed")) { mode = 2; - } else if (!strcmp(a->argv[3], "failed")) { + } else if (!strcasecmp(a->argv[3], "failed")) { mode = 1; - } else if (!strcmp(a->argv[3], "all")) { + } else if (!strcasecmp(a->argv[3], "all")) { mode = 0; } else { return CLI_SHOWUSAGE; @@ -950,7 +950,7 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct return NULL; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option, a->n); + return ast_cli_complete(a->word, option, -1); } return NULL; case CLI_HANDLER: @@ -958,10 +958,10 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct /* verify input */ if (a->argc < 4 || a->argc > 5) { return CLI_SHOWUSAGE; - } else if (!strcmp(a->argv[3], "xml")) { + } else if (!strcasecmp(a->argv[3], "xml")) { type = "xml"; isxml = 1; - } else if (!strcmp(a->argv[3], "txt")) { + } else if (!strcasecmp(a->argv[3], "txt")) { type = "txt"; } else { return CLI_SHOWUSAGE; -- cgit v1.2.3