[Asterisk-code-review] main/test: Use ast cli completion add. (asterisk[13])
Jenkins2
asteriskteam at digium.com
Tue Mar 20 08:50:57 CDT 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8580 )
Change subject: main/test: Use ast_cli_completion_add.
......................................................................
main/test: Use ast_cli_completion_add.
Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b
---
M main/test.c
1 file changed, 34 insertions(+), 34 deletions(-)
Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/main/test.c b/main/test.c
index d22f2eb..3fb1074 100644
--- a/main/test.c
+++ b/main/test.c
@@ -693,40 +693,40 @@
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 */
@@ -751,22 +751,22 @@
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");
@@ -810,16 +810,16 @@
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:
@@ -828,7 +828,7 @@
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 */
@@ -879,7 +879,7 @@
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:
@@ -887,11 +887,11 @@
/* 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;
@@ -952,7 +952,7 @@
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:
@@ -960,10 +960,10 @@
/* 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;
--
To view, visit https://gerrit.asterisk.org/8580
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b
Gerrit-Change-Number: 8580
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180320/f7070ffc/attachment-0001.html>
More information about the asterisk-code-review
mailing list