[asterisk-commits] rizzo: branch rizzo/astobj2 r47593 - /team/rizzo/astobj2/main/cli.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 14 03:40:59 MST 2006


Author: rizzo
Date: Tue Nov 14 04:40:58 2006
New Revision: 47593

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47593
Log:
convert "core show modules" to the new cli format
(and fix completion as well)


Modified:
    team/rizzo/astobj2/main/cli.c

Modified: team/rizzo/astobj2/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/cli.c?view=diff&rev=47593&r1=47592&r2=47593
==============================================================================
--- team/rizzo/astobj2/main/cli.c (original)
+++ team/rizzo/astobj2/main/cli.c Tue Nov 14 04:40:58 2006
@@ -335,10 +335,6 @@
 	return 0;
 }
 
-static char modlist_help[] =
-"Usage: core show modules [like keyword]\n"
-"       Shows Asterisk modules currently in use, and usage statistics.\n";
-
 static char uptime_help[] =
 "Usage: core show uptime [seconds]\n"
 "       Shows Asterisk uptime information.\n"
@@ -414,22 +410,44 @@
 /* core show modules [like keyword] */
 static int handle_modlist(int fd, int argc, char *argv[])
 {
-	char *like = "";
-	if (argc != 3 && argc != 5)
-		return RESULT_SHOWUSAGE;
-	else if (argc == 5) {
-		if (strcmp(argv[3],"like")) 
+	struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1];
+	char *like;
+	struct ast_cli_args *a;
+
+	switch(argc) {
+	case CLI_CMD_STRING:
+		return (int)"core show modules";
+
+	case CLI_USAGE:
+		return (int)
+			"Usage: core show modules [like keyword]\n"
+			"       Shows Asterisk modules currently in use, and usage statistics.\n";
+
+	case CLI_GENERATE:
+		a = (struct ast_cli_args *)argv[0];
+		if (a->pos == e->args)
+			return (int)(a->n == 0 ? strdup("like") : NULL);
+		else if (a->pos == e->args+1 && strcasestr(a->line," like "))
+			return (int)ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
+		else
+			return (int)NULL;
+
+	default:	/* we are guaranteed to have argc >= e->args */
+		if (argc == e->args)
+			like = "";
+		else if (argc == e->args + 2 && !strcmp(argv[e->args],"like"))
+			like = argv[e->args + 1];
+		else
 			return RESULT_SHOWUSAGE;
-		like = argv[4];
-	}
 		
-	ast_mutex_lock(&climodentrylock);
-	climodentryfd = fd; /* global, protected by climodentrylock */
-	ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
-	ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
-	climodentryfd = -1;
-	ast_mutex_unlock(&climodentrylock);
-	return RESULT_SUCCESS;
+		ast_mutex_lock(&climodentrylock);
+		climodentryfd = fd; /* global, protected by climodentrylock */
+		ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
+		ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
+		climodentryfd = -1;
+		ast_mutex_unlock(&climodentrylock);
+		return RESULT_SUCCESS;
+	}
 }
 #undef MODLIST_FORMAT
 #undef MODLIST_FORMAT2
@@ -855,11 +873,6 @@
 	return ast_module_helper(line, word, pos, state, 2, 1);
 }
 
-static char *complete_mod_4(const char *line, const char *word, int pos, int state)
-{
-	return ast_module_helper(line, word, pos, state, 3, 0);
-}
-
 static char *complete_fn(const char *line, const char *word, int pos, int state)
 {
 	char *c;
@@ -1004,13 +1017,7 @@
 	handle_logger_mute, "Toggle logging output to a console",
 	logger_mute_help },
 
-	{ { "core", "show", "modules", NULL },
-	handle_modlist, "List modules and info",
-	modlist_help },
-
-	{ { "core", "show", "modules", "like", NULL },
-	handle_modlist, "List modules and info",
-	modlist_help, complete_mod_4 },
+	NEW_CLI(handle_modlist, "List modules and info"),
 
 	{ { "load", NULL },
 	handle_load, "Load a module by name",



More information about the asterisk-commits mailing list