comparison toys/other/help.c @ 1232:4654f241ccbe draft

Add help -a (to show all commands) and -h (to produce HTML output).
author Rob Landley <rob@landley.net>
date Fri, 28 Mar 2014 17:48:02 -0500
parents 34ac05521d94
children
comparison
equal deleted inserted replaced
1231:ee5a6875d695 1232:4654f241ccbe
2 * 2 *
3 * Copyright 2007 Rob Landley <rob@landley.net> 3 * Copyright 2007 Rob Landley <rob@landley.net>
4 * 4 *
5 * Often a shell builtin. 5 * Often a shell builtin.
6 6
7 USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN)) 7 USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
8 8
9 config HELP 9 config HELP
10 bool "help" 10 bool "help"
11 default y 11 default y
12 depends on TOYBOX_HELP 12 depends on TOYBOX_HELP
13 help 13 help
14 usage: help [command] 14 usage: help [command]
15 15
16 Show usage information for toybox commands. 16 Show usage information for toybox commands.
17 Run "toybox" with no arguments for a list of available commands. 17 Run "toybox" with no arguments for a list of available commands.
18
19 config HELP_EXTRAS
20 bool "help -ah"
21 default y
22 depends on TOYBOX
23 depends on HELP
24 help
25 usage: help [-ah]
26
27 -a All commands
28 -h HTML output
18 */ 29 */
19 30
31 #define FOR_help
32 #include "toys.h"
20 33
21 #include "toys.h" 34 static void do_help(struct toy_list *t)
35 {
36 if (toys.optflags & FLAG_h)
37 xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
38
39 toys.which = t;
40 show_help();
41
42 if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
43 }
44
45 // The simple help is just toys.which = toy_find("name"); show_help();
46 // But iterating through html output and all commands is a big more
22 47
23 void help_main(void) 48 void help_main(void)
24 { 49 {
25 struct toy_list *t = toy_find(*toys.optargs); 50 int i;
51
52 if (!(toys.optflags & FLAG_a)) {
53 struct toy_list *t = toys.which;
26 54
27 if (!t) error_exit("Unknown command '%s'", *toys.optargs); 55 if (*toys.optargs && !(t = toy_find(*toys.optargs)))
28 toys.which = t; 56 error_exit("Unknown command '%s'", *toys.optargs);
29 show_help(); 57 do_help(t);
58 return;
59 }
60
61 if (toys.optflags & FLAG_h) {
62 xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n");
63 for (i=0; i < toys.toycount; i++)
64 xprintf("<a href=\"#%s\">%s</a>\n", toy_list[i].name,
65 toy_list[i].name);
66 xprintf("</p>\n");
67 }
68
69 for (i = 0; i < toys.toycount; i++) {
70 if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n");
71 do_help(toy_list+i);
72 if (toys.optflags & FLAG_h) xprintf("</pre>\n");
73 }
74
75 if (toys.optflags & FLAG_h) xprintf("</html>");
30 } 76 }