[asterisk-commits] russell: trunk r72937 - /trunk/main/cli.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 2 15:42:15 CDT 2007
Author: russell
Date: Mon Jul 2 15:42:14 2007
New Revision: 72937
URL: http://svn.digium.com/view/asterisk?view=rev&rev=72937
Log:
Add a CLI command to output docs on CLI commands to a file
Modified:
trunk/main/cli.c
Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=72937&r1=72936&r2=72937
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Mon Jul 2 15:42:14 2007
@@ -972,6 +972,10 @@
static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+#ifdef AST_DEVMODE
+static char *handle_core_dump_clidocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+#endif
+
static struct ast_cli_entry cli_cli[] = {
/* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */
NEW_CLI(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
@@ -1010,6 +1014,10 @@
{ { "soft", "hangup", NULL },
handle_softhangup, "Request a hangup on a given channel",
softhangup_help, complete_ch_3 },
+
+#ifdef AST_DEVMODE
+ NEW_CLI(handle_core_dump_clidocs, "Dump CLI command documentation in LaTeX format"),
+#endif
};
/*!
@@ -1450,6 +1458,65 @@
return RESULT_SUCCESS;
}
+#ifdef AST_DEVMODE
+static char *handle_core_dump_clidocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_cli_entry *cli;
+ FILE *f;
+ const char *fn = "/tmp/ast_cli_commands.tex";
+ struct cli_iterator i = { NULL, NULL};
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core dump clidocs";
+ e->usage =
+ "Usage: core dump clidocs\n"
+ " Dump CLI command documentation to /tmp/ast_cli_commands.tex.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ 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 \"core dump clidocs\" CLI command. Any manual edits will be lost.\n");
+
+ AST_LIST_LOCK(&helpers);
+ while ((cli = cli_next(&i))) {
+ /* Hide commands that start with '_' */
+ if (cli->_full_cmd[0] == '_')
+ continue;
+ /* Hide commands that are marked as deprecated. */
+ if (cli->deprecated)
+ 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",
+ cli->_full_cmd, cli->summary, cli->usage);
+ }
+ AST_LIST_UNLOCK(&helpers);
+
+ fclose(f);
+
+ ast_cli(a->fd, "Documentation has been dumped to %s\n", fn);
+
+ return CLI_SUCCESS;
+}
+#endif /* AST_DEVMODE */
+
static char *parse_args(const char *s, int *argc, char *argv[], int max, int *trailingwhitespace)
{
char *dup, *cur;
More information about the asterisk-commits
mailing list