[Asterisk-code-review] cli: Enable ast cli completion add on public completion gene... (asterisk[15])

Corey Farrell asteriskteam at digium.com
Thu Mar 15 06:27:34 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/8528


Change subject: cli: Enable ast_cli_completion_add on public completion generators.
......................................................................

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
---
M main/cli.c
M main/pbx_app.c
2 files changed, 35 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/28/8528/1

diff --git a/main/cli.c b/main/cli.c
index b34da19..556c09b 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1682,8 +1682,15 @@
 	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;
 }
@@ -1709,9 +1716,16 @@
 		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 ec6bc75..df8126c 100644
--- a/main/pbx_app.c
+++ b/main/pbx_app.c
@@ -275,7 +275,7 @@
 		 * 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 @@
 	AST_RWLIST_RDLOCK(&apps);
 	AST_RWLIST_TRAVERSE(&apps, app, list) {
 		cmp = strncasecmp(word, app->name, wordlen);
-		if (cmp > 0) {
-			continue;
-		}
-		if (!cmp) {
-			/* Found match. */
-			if (++which <= state) {
-				/* Not enough matches. */
-				continue;
-			}
-			ret = ast_strdup(app->name);
+		if (cmp < 0) {
+			/* No more matches. */
 			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);
 

-- 
To view, visit https://gerrit.asterisk.org/8528
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ff311f0873099be0e43a3dc5415c0cd06d15756
Gerrit-Change-Number: 8528
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180315/ccda0b57/attachment.html>


More information about the asterisk-code-review mailing list