diff options
author | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-11-14 16:55:27 +0000 |
---|---|---|
committer | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-11-14 16:55:27 +0000 |
commit | 4956491321c550c805a910a434bcd929dc410795 (patch) | |
tree | f4c53bd04ac0103047457c09028215914c328411 /main/cli.c | |
parent | 717e42ac586ac0bc7f29fc2709ce106ce922a267 (diff) |
partly convert to new style set-verbose, with completion fixes
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@47619 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/cli.c')
-rw-r--r-- | main/cli.c | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/main/cli.c b/main/cli.c index 1e361b798..cac7d7c65 100644 --- a/main/cli.c +++ b/main/cli.c @@ -105,12 +105,6 @@ static char reload_help[] = " Reloads configuration files for all listed modules which support\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[] = "Usage: logger mute\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[]) { /* "module reload [mod_1 ... mod_N]" */ - int x; - int res; - if (argc < 2) - return RESULT_SHOWUSAGE; - if (argc > 2) { - for (x = 2; x < argc; x++) { - res = ast_module_reload(argv[x]); + struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1]; + + if (argc == e->args) + ast_module_reload(NULL); + else { + int x; + for (x = e->args; x < argc; x++) { + int res = ast_module_reload(argv[x]); switch(res) { case 0: 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; } } - } else - ast_module_reload(NULL); + } 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[]) { + /* "core set verbose [atleast] <n>" */ int oldval = option_verbose; int newlevel; 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)) - return RESULT_SHOWUSAGE; + switch (argc) { + case CLI_CMD_STRING: + return (int)"core set verbose"; - if (!strcasecmp(argv[3], "atleast")) - atleast = 1; + case CLI_USAGE: + 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) { - if (argc > 4) - return RESULT_SHOWUSAGE; + case CLI_GENERATE: + a = (struct ast_cli_args *)argv[0]; + if (a->pos > e->args) + return NULL; + return (int)ast_cli_complete(a->word, choices, a->n); + } + /* all the above return, so we proceed with the handler. + * we are guaranteed to be called with argc >= e->args; + */ - option_verbose = atoi(argv[3]); - } else { - if (argc < 5) - return RESULT_SHOWUSAGE; + if (argc < e->args + 1) + return RESULT_SHOWUSAGE; - newlevel = atoi(argv[4]); - if (newlevel > option_verbose) - option_verbose = newlevel; - } + 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) ast_cli(fd, "Verbosity is now OFF\n"); 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"), - { { "core", "set", "verbose", NULL }, - handle_verbose, "Set level of verboseness", - verbose_help }, + NEW_CLI(handle_verbose, "Set level of verboseness"), { { "group", "show", "channels", NULL }, group_show_channels, "Display active channels with group(s)", |