summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-06-25 20:43:26 +0000
committerMatthew Jordan <mjordan@digium.com>2012-06-25 20:43:26 +0000
commit5d31fb2dd258559d851b83f9eedb7f4e1452b071 (patch)
tree366750ca9bbf5a262062f5b20bc4d6a16b5f749a
parentbebdbf33819aad5b7bf181f3fddd2fb25bea59b1 (diff)
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) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369386 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--main/manager.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/main/manager.c b/main/manager.c
index 412624706..3eb113322 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -6896,21 +6896,19 @@ static char *handle_manager_show_events(struct ast_cli_entry *e, int cmd, struct
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);
@@ -6919,6 +6917,27 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct
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))) {
ast_cli(a->fd, "Could not find event '%s'\n", a->argv[3]);
ao2_ref(events, -1);