[asterisk-commits] mjordan: trunk r369386 - /trunk/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 25 15:43:30 CDT 2012


Author: mjordan
Date: Mon Jun 25 15:43:26 2012
New Revision: 369386

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=369386
Log:
Update "manager show event" to support tab completion

Thank you rmudgett for pointing out that I was missing this in the initial
check-in for AMI event documentation (r369346)

Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=369386&r1=369385&r2=369386
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Mon Jun 25 15:43:26 2012
@@ -6896,27 +6896,46 @@
 static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ao2_container *events;
+	struct ao2_iterator it_events;
 	struct ast_xml_doc_item *item, *temp;
+	int length;
+	int which;
+	char *match = NULL;
 	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
 
-	switch (cmd) {
-	case CLI_INIT:
+	if (cmd == CLI_INIT) {
 		e->command = "manager show event";
 		e->usage =
 			"Usage: manager show event <eventname>\n"
 			"       Provides a detailed description a Manager interface event.\n";
 		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc != 4) {
-		return CLI_SHOWUSAGE;
 	}
 
 	events = ao2_global_obj_ref(event_docs);
 	if (!events) {
 		ast_cli(a->fd, "No manager event documentation loaded\n");
 		return CLI_SUCCESS;
+	}
+
+	if (cmd == CLI_GENERATE) {
+		length = strlen(a->word);
+		which = 0;
+		it_events = ao2_iterator_init(events, 0);
+		while ((item = ao2_iterator_next(&it_events))) {
+			if (!strncasecmp(a->word, item->name, length) && ++which > a->n) {
+				match = ast_strdup(item->name);
+				ao2_ref(item, -1);
+				break;
+			}
+			ao2_ref(item, -1);
+		}
+		ao2_iterator_destroy(&it_events);
+		ao2_ref(events, -1);
+		return match;
+	}
+
+	if (a->argc != 4) {
+		return CLI_SHOWUSAGE;
 	}
 
 	if (!(item = ao2_find(events, a->argv[3], OBJ_KEY))) {




More information about the asterisk-commits mailing list