aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-02 19:29:50 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-02 19:29:50 +0000
commitbf47a7320bf10f28cda4de11a2c3b7a4608985f3 (patch)
tree7781349ce1750d05899835c1ccf421de8fa50b1d
parentc173ac08242e1fb3ae1278ffc7891658b771f7ad (diff)
Add a CLI command to export the AGI command docs
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@72931 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--res/res_agi.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index cd7e0a928..13755119f 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -1673,6 +1673,71 @@ static int help_workhorse(int fd, char *match[])
return 0;
}
+#ifdef AST_DEVMODE
+static char *handle_agi_dump_commanddocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ FILE *f;
+ char *command_name = NULL;
+ const char *fn = "/tmp/ast_agi_commands.tex";
+ int i;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "agi dump commanddocs";
+ e->usage =
+ "Usage: agi dump commanddocs [command]\n"
+ " Dump manager action documentation to /tmp/ast_agi_commands.tex.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc == e->args + 1)
+ command_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");
+
+ /* XXX Not thread safe :( */
+ for (i = 0; i < ARRAY_LEN(commands); i++) {
+ struct agi_command *command;
+ char fullcmd[80];
+
+ command = &commands[i];
+ ast_join(fullcmd, sizeof(fullcmd), command->cmda);
+
+ if (command_name && strcasecmp(fullcmd, command_name))
+ continue;
+
+ fprintf(f, "\\section{%s}\n"
+ "\\subsection{Summary}\n"
+ "\\begin{verbatim}\n"
+ "%s\n"
+ "\\end{verbatim}\n"
+ "\\subsection{Usage}\n"
+ "\\begin{verbatim}\n"
+ "%s\n"
+ "\\end{verbatim}\n\n\n",
+ fullcmd, command->summary, command->usage);
+
+ if (command_name)
+ break;
+ }
+
+ fclose(f);
+
+ ast_cli(a->fd, "Documentation has been dumped to %s\n", fn);
+
+ return CLI_SUCCESS;
+}
+#endif /* AST_DEVMODE */
+
int ast_agi_register(agi_command *agi)
{
int x;
@@ -2164,6 +2229,10 @@ static struct ast_cli_entry cli_agi[] = {
{ { "agi", "dumphtml", NULL },
handle_agidumphtml, "Dumps a list of agi commands in html format",
dumpagihtml_help },
+
+#ifdef AST_DEVMODE
+ NEW_CLI(handle_agi_dump_commanddocs, "Dump agi command documentation in LaTeX format"),
+#endif
};
static int unload_module(void)