mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-29 15:36:13 +00:00 
			
		
		
		
	partly convert to new style set-verbose, with completion fixes
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47619 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		
							
								
								
									
										82
									
								
								main/cli.c
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								main/cli.c
									
									
									
									
									
								
							| @@ -105,12 +105,6 @@ static char reload_help[] = | |||||||
| "       Reloads configuration files for all listed modules which support\n" | "       Reloads configuration files for all listed modules which support\n" | ||||||
| "       reloading, or for all supported modules if none are listed.\n"; | "       reloading, or for all supported modules if none are listed.\n"; | ||||||
|  |  | ||||||
| static char verbose_help[] =  |  | ||||||
| "Usage: core set verbose <level>\n" |  | ||||||
| "       Sets level of verbose messages to be displayed.  0 means\n" |  | ||||||
| "       no messages should be displayed. Equivalent to -v[v[v...]]\n" |  | ||||||
| "       on startup\n"; |  | ||||||
|  |  | ||||||
| static char logger_mute_help[] =  | static char logger_mute_help[] =  | ||||||
| "Usage: logger mute\n" | "Usage: logger mute\n" | ||||||
| "       Disables logging output to the current console, making it possible to\n" | "       Disables logging output to the current console, making it possible to\n" | ||||||
| @@ -148,13 +142,14 @@ static int handle_load_deprecated(int fd, int argc, char *argv[]) | |||||||
| static int handle_reload(int fd, int argc, char *argv[]) | static int handle_reload(int fd, int argc, char *argv[]) | ||||||
| { | { | ||||||
| 	/* "module reload [mod_1 ... mod_N]" */ | 	/* "module reload [mod_1 ... mod_N]" */ | ||||||
|  | 	struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1]; | ||||||
|  |  | ||||||
|  | 	if (argc == e->args) | ||||||
|  | 		ast_module_reload(NULL); | ||||||
|  | 	else { | ||||||
| 		int x; | 		int x; | ||||||
| 	int res; | 		for (x = e->args; x < argc; x++) { | ||||||
| 	if (argc < 2) | 			int res = ast_module_reload(argv[x]); | ||||||
| 		return RESULT_SHOWUSAGE; |  | ||||||
| 	if (argc > 2) {  |  | ||||||
| 		for (x = 2; x < argc; x++) { |  | ||||||
| 			res = ast_module_reload(argv[x]); |  | ||||||
| 			switch(res) { | 			switch(res) { | ||||||
| 			case 0: | 			case 0: | ||||||
| 				ast_cli(fd, "No such module '%s'\n", argv[x]); | 				ast_cli(fd, "No such module '%s'\n", argv[x]); | ||||||
| @@ -164,8 +159,7 @@ static int handle_reload(int fd, int argc, char *argv[]) | |||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} else | 	} | ||||||
| 		ast_module_reload(NULL); |  | ||||||
| 	return RESULT_SUCCESS; | 	return RESULT_SUCCESS; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -176,29 +170,53 @@ static int handle_reload_deprecated(int fd, int argc, char *argv[]) | |||||||
|  |  | ||||||
| static int handle_verbose(int fd, int argc, char *argv[]) | static int handle_verbose(int fd, int argc, char *argv[]) | ||||||
| { | { | ||||||
|  | 	/* "core set verbose [atleast] <n>" */ | ||||||
| 	int oldval = option_verbose; | 	int oldval = option_verbose; | ||||||
| 	int newlevel; | 	int newlevel; | ||||||
| 	int atleast = 0; | 	int atleast = 0; | ||||||
|  | 	struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1]; | ||||||
|  | 	static char *choices[] = { "off", "atleast", NULL }; | ||||||
|  | 	struct ast_cli_args *a; | ||||||
|  |  | ||||||
| 	if ((argc < 4) || (argc > 5)) | 	switch (argc) { | ||||||
| 		return RESULT_SHOWUSAGE; | 	case CLI_CMD_STRING: | ||||||
|  | 		return (int)"core set verbose"; | ||||||
|  |  | ||||||
| 	if (!strcasecmp(argv[3], "atleast")) | 	case CLI_USAGE: | ||||||
| 		atleast = 1; | 		return (int) | ||||||
|  | 			"Usage: core set verbose [atleast] <level>\n" | ||||||
|  | 			"       core set verbose off\n" | ||||||
|  | 			"       Sets level of verbose messages to be displayed.  0 or off means\n" | ||||||
|  | 			"       no messages should be displayed. Equivalent to -v[v[v...]]\n" | ||||||
|  | 			"       on startup\n"; | ||||||
|  |  | ||||||
| 	if (!atleast) { | 	case CLI_GENERATE: | ||||||
| 		if (argc > 4) | 		a = (struct ast_cli_args *)argv[0]; | ||||||
| 			return RESULT_SHOWUSAGE; | 		if (a->pos > e->args) | ||||||
|  | 			return NULL; | ||||||
| 		option_verbose = atoi(argv[3]); | 		return (int)ast_cli_complete(a->word, choices, a->n); | ||||||
| 	} else { |  | ||||||
| 		if (argc < 5) |  | ||||||
| 			return RESULT_SHOWUSAGE; |  | ||||||
|  |  | ||||||
| 		newlevel = atoi(argv[4]); |  | ||||||
| 		if (newlevel > option_verbose) |  | ||||||
| 			option_verbose = newlevel; |  | ||||||
| 	} | 	} | ||||||
|  | 	/* all the above return, so we proceed with the handler. | ||||||
|  | 	 * we are guaranteed to be called with argc >= e->args; | ||||||
|  | 	 */ | ||||||
|  |  | ||||||
|  | 	if (argc < e->args + 1) | ||||||
|  | 		return RESULT_SHOWUSAGE; | ||||||
|  |  | ||||||
|  | 	if (argc == e->args + 1 && !strcasecmp(argv[e->args], "off")) { | ||||||
|  | 		newlevel = 0; | ||||||
|  | 		goto done; | ||||||
|  | 	} | ||||||
|  | 	if (!strcasecmp(argv[e->args], "atleast")) | ||||||
|  | 		atleast = 1; | ||||||
|  | 	if (argc != e->args + atleast + 1) | ||||||
|  | 		return RESULT_SHOWUSAGE; | ||||||
|  | 	if (sscanf(argv[e->args + atleast], "%d", &newlevel) != 1) | ||||||
|  | 		return RESULT_SHOWUSAGE; | ||||||
|  |  | ||||||
|  | done: | ||||||
|  | 	if (!atleast || newlevel > option_verbose) | ||||||
|  | 		option_verbose = newlevel; | ||||||
| 	if (oldval > 0 && option_verbose == 0) | 	if (oldval > 0 && option_verbose == 0) | ||||||
| 		ast_cli(fd, "Verbosity is now OFF\n"); | 		ast_cli(fd, "Verbosity is now OFF\n"); | ||||||
| 	else if (option_verbose > 0) { | 	else if (option_verbose > 0) { | ||||||
| @@ -1112,9 +1130,7 @@ static struct ast_cli_entry cli_cli[] = { | |||||||
|  |  | ||||||
| 	NEW_CLI(handle_set_debug, "Set level of debug chattiness"), | 	NEW_CLI(handle_set_debug, "Set level of debug chattiness"), | ||||||
|  |  | ||||||
| 	{ { "core", "set", "verbose", NULL }, | 	NEW_CLI(handle_verbose, "Set level of verboseness"), | ||||||
| 	handle_verbose, "Set level of verboseness", |  | ||||||
| 	verbose_help }, |  | ||||||
|  |  | ||||||
| 	{ { "group", "show", "channels", NULL }, | 	{ { "group", "show", "channels", NULL }, | ||||||
| 	group_show_channels, "Display active channels with group(s)", | 	group_show_channels, "Display active channels with group(s)", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user