aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-03-28 17:48:02 -0500
committerRob Landley <rob@landley.net>2014-03-28 17:48:02 -0500
commit36aa7d7382f64695ef003e5616890188b9f1f61b (patch)
tree5ca460327629086457f333aa5364c11dbf6ff0e1 /toys
parente9a41fc5ae51ccf7bd5677773bfe72d01f06b3cd (diff)
downloadtoybox-36aa7d7382f64695ef003e5616890188b9f1f61b.tar.gz
Add help -a (to show all commands) and -h (to produce HTML output).
Diffstat (limited to 'toys')
-rw-r--r--toys/other/help.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/toys/other/help.c b/toys/other/help.c
index e16abaab..15f8271e 100644
--- a/toys/other/help.c
+++ b/toys/other/help.c
@@ -4,7 +4,7 @@
*
* Often a shell builtin.
-USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
+USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
config HELP
bool "help"
@@ -15,16 +15,62 @@ config HELP
Show usage information for toybox commands.
Run "toybox" with no arguments for a list of available commands.
-*/
+config HELP_EXTRAS
+ bool "help -ah"
+ default y
+ depends on TOYBOX
+ depends on HELP
+ help
+ usage: help [-ah]
+
+ -a All commands
+ -h HTML output
+*/
+#define FOR_help
#include "toys.h"
-void help_main(void)
+static void do_help(struct toy_list *t)
{
- struct toy_list *t = toy_find(*toys.optargs);
+ if (toys.optflags & FLAG_h)
+ xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
- if (!t) error_exit("Unknown command '%s'", *toys.optargs);
toys.which = t;
show_help();
+
+ if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
+}
+
+// The simple help is just toys.which = toy_find("name"); show_help();
+// But iterating through html output and all commands is a big more
+
+void help_main(void)
+{
+ int i;
+
+ if (!(toys.optflags & FLAG_a)) {
+ struct toy_list *t = toys.which;
+
+ if (*toys.optargs && !(t = toy_find(*toys.optargs)))
+ error_exit("Unknown command '%s'", *toys.optargs);
+ do_help(t);
+ return;
+ }
+
+ if (toys.optflags & FLAG_h) {
+ xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n");
+ for (i=0; i < toys.toycount; i++)
+ xprintf("<a href=\"#%s\">%s</a>\n", toy_list[i].name,
+ toy_list[i].name);
+ xprintf("</p>\n");
+ }
+
+ for (i = 0; i < toys.toycount; i++) {
+ if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n");
+ do_help(toy_list+i);
+ if (toys.optflags & FLAG_h) xprintf("</pre>\n");
+ }
+
+ if (toys.optflags & FLAG_h) xprintf("</html>");
}