[asterisk-commits] rizzo: trunk r47609 - /trunk/main/cli.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Nov 14 09:09:08 MST 2006
Author: rizzo
Date: Tue Nov 14 10:09:08 2006
New Revision: 47609
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47609
Log:
new-style for 'core show uptime', include 'complete' support and better error checking
Modified:
trunk/main/cli.c
Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=47609&r1=47608&r2=47609
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Tue Nov 14 10:09:08 2006
@@ -402,11 +402,6 @@
return 0;
}
-static char uptime_help[] =
-"Usage: core show uptime [seconds]\n"
-" Shows Asterisk uptime information.\n"
-" The seconds word returns the uptime in seconds only.\n";
-
static void print_uptimestr(int fd, time_t timeval, const char *prefix, int printsec)
{
int x; /* the main part - years, weeks, etc. */
@@ -461,12 +456,33 @@
static int handle_showuptime(int fd, int argc, char *argv[])
{
- /* 'show uptime [seconds]' */
- time_t curtime = time(NULL);
- int printsec = (argc == 4 && !strcasecmp(argv[3],"seconds"));
-
- if (argc != 3 && !printsec)
- return RESULT_SHOWUSAGE;
+ struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1];
+ time_t curtime;
+ int printsec;
+ struct ast_cli_args *a;
+
+ switch (argc) {
+ case CLI_CMD_STRING:
+ return (int)"core show uptime";
+
+ case CLI_USAGE:
+ return (int)
+ "Usage: core show uptime [seconds]\n"
+ " Shows Asterisk uptime information.\n"
+ " The seconds word returns the uptime in seconds only.\n";
+
+ case CLI_GENERATE:
+ a = (struct ast_cli_args *)argv[0];
+ return (int)((a->pos > e->args || a->n > 0) ? NULL : "seconds");
+ }
+ /* regular handler */
+ if (argc == e->args+1 && !strcasecmp(argv[e->args],"seconds"))
+ printsec = 1;
+ else if (argc == e->args)
+ printsec = 0;
+ else
+ return RESULT_SHOWUSAGE;
+ curtime = time(NULL);
if (ast_startuptime)
print_uptimestr(fd, curtime - ast_startuptime, "System uptime", printsec);
if (ast_lastreloadtime)
@@ -1169,9 +1185,7 @@
handle_unload, "Unload a module by name",
unload_help, complete_mod_3_nr, &cli_module_unload_deprecated },
- { { "core", "show", "uptime", NULL },
- handle_showuptime, "Show uptime information",
- uptime_help },
+ NEW_CLI(handle_showuptime, "Show uptime information"),
{ { "soft", "hangup", NULL },
handle_softhangup, "Request a hangup on a given channel",
More information about the asterisk-commits
mailing list