[svn-commits] rizzo: branch rizzo/astobj2 r47592 - in /team/rizzo/astobj2: include/asterisk...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Nov 14 03:23:50 MST 2006


Author: rizzo
Date: Tue Nov 14 04:23:49 2006
New Revision: 47592

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47592
Log:
convert "core set debug" to the new style, to see how it looks.
On passing, add an argument to the NEW_CLI macro so we are forced
to put a summary for the command.


Modified:
    team/rizzo/astobj2/include/asterisk/cli.h
    team/rizzo/astobj2/main/astobj2.c
    team/rizzo/astobj2/main/cli.c

Modified: team/rizzo/astobj2/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/include/asterisk/cli.h?view=diff&rev=47592&r1=47591&r2=47592
==============================================================================
--- team/rizzo/astobj2/include/asterisk/cli.h (original)
+++ team/rizzo/astobj2/include/asterisk/cli.h Tue Nov 14 04:23:49 2006
@@ -81,7 +81,8 @@
 	int new_setdebug(int fd, int argc, char *argv[]);
 
 	...
-	NEW_CLI(new_setdebug)	// this is how we create the entry to register
+	// this is how we create the entry to register
+	NEW_CLI(new_setdebug, "short description")
 	...
 
    Called with the default arguments (argc > 0), the new_handler implements
@@ -179,7 +180,7 @@
 	AST_LIST_ENTRY(ast_cli_entry) list;
 };
 
-#define NEW_CLI(fn)	{ .handler = (old_cli_fn)fn }
+#define NEW_CLI(fn, txt)	{ .handler = (old_cli_fn)fn, .summary = txt }
 
 /* argument for new-style CLI handler */
 struct ast_cli_args {

Modified: team/rizzo/astobj2/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/astobj2.c?view=diff&rev=47592&r1=47591&r2=47592
==============================================================================
--- team/rizzo/astobj2/main/astobj2.c (original)
+++ team/rizzo/astobj2/main/astobj2.c Tue Nov 14 04:23:49 2006
@@ -702,7 +702,7 @@
 	{ { "astobj2", "stats", NULL },
 	handle_astobj2_stats, "Print astobj2 statistics", },
 	{ { "astobj2", "test", NULL } , handle_astobj2_test, "Test astobj2", },
-	NEW_CLI(test_new_cli),
+	NEW_CLI(test_new_cli, "sample new-cli command"),
 };
 
 int astobj2_init(void);

Modified: team/rizzo/astobj2/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/cli.c?view=diff&rev=47592&r1=47591&r2=47592
==============================================================================
--- team/rizzo/astobj2/main/cli.c (original)
+++ team/rizzo/astobj2/main/cli.c Tue Nov 14 04:23:49 2006
@@ -111,13 +111,6 @@
 "       no messages should be displayed. Equivalent to -v[v[v...]]\n"
 "       on startup\n";
 
-static char debug_help[] = 
-"Usage: core set debug <level> [filename]\n"
-"       Sets level of core debug messages to be displayed.  0 means\n"
-"       no messages should be displayed.  Equivalent to -d[d[d...]]\n"
-"       on startup.  If filename is specified, debugging will be\n"
-"       limited to just that file.\n";
-
 static char nodebug_help[] = 
 "Usage: core set no debug\n"
 "       Turns off core debug messages.\n";
@@ -211,67 +204,69 @@
 
 static int handle_debug(int fd, int argc, char *argv[])
 {
+	struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1];
 	int oldval = option_debug;
 	int newlevel;
 	int atleast = 0;
 	char *filename = '\0';
 
-	if ((argc < 4) || (argc > 6))
-		return RESULT_SHOWUSAGE;
-
-	if (!strcasecmp(argv[3], "atleast"))
-		atleast = 1;
-
-	if (!atleast) {
-		if (argc > 5)
+	switch(argc) {
+	case CLI_CMD_STRING:
+		return (int)"core set debug";
+
+	case CLI_USAGE:
+		return (int)
+			"Usage: core set debug [atleast] <level> [filename]\n"
+			"       Sets level of core debug messages to be displayed.  0 means\n"
+			"       no messages should be displayed.  Equivalent to -d[d[d...]]\n"
+			"       on startup.  If filename is specified, debugging will be\n"
+			"       limited to just that file.\n";
+
+	case CLI_GENERATE:
+		/* at the moment don't do anything, though could well explode the
+		 * list of available filenames
+		 */
+		return (int)NULL;
+
+	default: /* we are guaranteed to be called with argc >= e->args; */
+
+		if (argc < e->args + 1)
 			return RESULT_SHOWUSAGE;
 
-		if (sscanf(argv[3], "%d", &newlevel) != 1)
+		if (!strcasecmp(argv[e->args], "atleast"))
+			atleast = 1;
+		if (argc > e->args + atleast + 2)
 			return RESULT_SHOWUSAGE;
-
-		if (argc == 4) {
+		if (sscanf(argv[e->args + atleast], "%d", &newlevel) != 1)
+			return RESULT_SHOWUSAGE;
+
+		if (argc == e->args + atleast + 1) {
 			debug_filename[0] = '\0';
 		} else {
-			filename = argv[4];
-			ast_copy_string(debug_filename, filename, sizeof(debug_filename));
-		}
-
-		option_debug = newlevel;
-	} else {
-		if (argc < 5 || argc > 6)
-			return RESULT_SHOWUSAGE;
-
-		if (sscanf(argv[4], "%d", &newlevel) != 1)
-			return RESULT_SHOWUSAGE;
-
-		if (argc == 6) {
-			debug_filename[0] = '\0';
-		} else {
-			filename = argv[4];
-			ast_copy_string(debug_filename, filename, sizeof(debug_filename));
-		}
-
-		if (newlevel > option_debug)
+			ast_copy_string(debug_filename, argv[e->args + atleast + 1], sizeof(debug_filename));
+		}
+
+		if (!atleast || newlevel > option_debug)
 			option_debug = newlevel;
-	}
-
-	if (oldval > 0 && option_debug == 0)
-		ast_cli(fd, "Core debug is now OFF\n");
-	else if (option_debug > 0) {
-		if (filename) {
-			if (oldval == option_debug)
-				ast_cli(fd, "Core debug is at least %d, file '%s'\n", option_debug, filename);
-			else
-				ast_cli(fd, "Core debug was %d and is now %d, file '%s'\n", oldval, option_debug, filename);
-		} else {
-			if (oldval == option_debug)
-				ast_cli(fd, "Core debug is at least %d\n", option_debug);
-			else
-				ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug);
-		}
-	}
-
-	return RESULT_SUCCESS;
+
+		if (oldval > 0 && option_debug == 0)
+			ast_cli(fd, "Core debug is now OFF\n");
+		else if (option_debug > 0) {
+			if (filename) {
+				if (oldval == option_debug)
+					ast_cli(fd, "Core debug is at least %d, file '%s'\n", option_debug, filename);
+				else
+					ast_cli(fd, "Core debug was %d and is now %d, file '%s'\n", oldval, option_debug, filename);
+			} else {
+				if (oldval == option_debug)
+					ast_cli(fd, "Core debug is at least %d\n", option_debug);
+				else
+					ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug);
+			}
+		}
+
+		return RESULT_SUCCESS;
+	}
 }
 
 static int handle_nodebug(int fd, int argc, char *argv[])
@@ -987,9 +982,7 @@
 	handle_nodebugchan, "Disable debugging on a channel",
 	nodebugchan_help, complete_ch_3 },
 
-	{ { "core", "set", "debug", NULL },
-	handle_debug, "Set level of debug chattiness",
-	debug_help },
+	NEW_CLI(handle_debug, "Set level of debug chattiness"),
 
 	{ { "core", "set", "no", "debug", NULL },
 	handle_nodebug, "Turns off debug chattiness",
@@ -1202,8 +1195,6 @@
 		}
 		*dst++ = NULL;
 		e->usage = (char *)(e->handler(-1, CLI_USAGE, args+1));
-		ast_verbose("running new-style CLI entry for %s\n", e->command);
-		sleep(1);
 	}
 	for (i = 0; e->cmda[i]; i++)
 		;



More information about the svn-commits mailing list