Add a CLI command to dump the built-in manager action documentation

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@72928 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant 2007-07-02 18:45:50 +00:00
parent 3371051d74
commit 1bb2c2a78f
1 changed files with 71 additions and 0 deletions

View File

@ -491,6 +491,73 @@ static int manager_displayconnects (struct mansession *s)
return ret;
}
#ifdef AST_DEVMODE
static char *handle_manager_dump_actiondocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct manager_action *action;
FILE *f;
char *action_name = NULL;
const char *fn = "/tmp/ast_manager_actiondocs.tex";
struct ast_str *authority = ast_str_alloca(80);
switch (cmd) {
case CLI_INIT:
e->command = "manager dump actiondocs";
e->usage =
"Usage: manager dump actiondocs [action]\n"
" Dump manager action documentation to /tmp/ast_manager_actiondocs.tex.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc == e->args + 1)
action_name = a->argv[e->args];
else if (a->argc != e->args)
return CLI_SHOWUSAGE;
if (!(f = fopen(fn, "w+"))) {
ast_cli(a->fd, "Unable to open %s for writing!\n", fn);
return CLI_FAILURE;
}
fprintf(f, "%% This file is automatically generated by the \"manager dump actiondocs\" CLI command. Any manual edits will be lost.\n");
ast_rwlock_rdlock(&actionlock);
for (action = first_action; action; action = action->next) {
if (action_name && strcasecmp(action->action, action_name))
continue;
fprintf(f, "\\section{%s}\n"
"\\subsection{Synopsis}\n"
"\\begin{verbatim}\n"
"%s\n"
"\\end{verbatim}\n"
"\\subsection{Authority}\n"
"\\begin{verbatim}\n"
"%s\n"
"\\end{verbatim}\n"
"\\subsection{Description}\n"
"\\begin{verbatim}\n"
"%s\n"
"\\end{verbatim}\n\n\n",
action->action, action->synopsis,
authority_to_str(action->authority, &authority),
action->description);
if (action_name)
break;
}
ast_rwlock_unlock(&actionlock);
fclose(f);
ast_cli(a->fd, "Documentation has been dumped to %s\n", fn);
return CLI_SUCCESS;
}
#endif /* AST_DEVMODE */
static int handle_showmancmd(int fd, int argc, char *argv[])
{
struct manager_action *cur;
@ -708,6 +775,10 @@ static struct ast_cli_entry cli_manager[] = {
{ { "manager", "debug", NULL },
handle_mandebug, "Show, enable, disable debugging of the manager code",
"Usage: manager debug [on|off]\n Show, enable, disable debugging of the manager code.\n", NULL, NULL },
#ifdef AST_DEVMODE
NEW_CLI(handle_manager_dump_actiondocs, "Dump manager action documentation in LaTeX format"),
#endif
};
/*