aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-02 20:42:14 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-02 20:42:14 +0000
commitcfb405413d902164d97cc1ca80bc59dc88539c5b (patch)
tree719df388c6a1aaaa22e663b87d0becd3e6d265b7 /main
parentf3c5a95dc9fe7d3669fda5a3114dd72718459d53 (diff)
Add a CLI command to output docs on CLI commands to a file
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@72937 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/cli.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/main/cli.c b/main/cli.c
index 7607793ae..cefee0e7e 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -972,6 +972,10 @@ static struct ast_cli_entry cli_module_unload_deprecated = NEW_CLI(handle_unload
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 @@ static struct ast_cli_entry cli_cli[] = {
{ { "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 @@ static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
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;