summaryrefslogtreecommitdiffstats
path: root/commands/help.c
diff options
context:
space:
mode:
authorHolger Schurig <holgerschurig@gmail.com>2014-05-13 10:28:42 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-14 10:03:43 +0200
commitf1f532084a6e9ee8225f047353999b459455df7e (patch)
treef2b8b1f25c5c630209c6970e3a7ce57a3d55d367 /commands/help.c
parentab23d0bb3f66cfb7a97a8aa6b8007687ed7a6925 (diff)
downloadbarebox-f1f532084a6e9ee8225f047353999b459455df7e.tar.gz
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very cumbersome/time consuming) to break it out. What is does is this: * each command has one short description, e.g. "list MUX configuration" * made sure the short descriptions start lowercase * each command has one usage. That string contains just the options, e.g. "[-npn]". It's not part of the long help text. * that is, it doesn't say "[OPTIONS]" anymore, every usable option is listed by character in this (short) option string (the long description is in the long help text, as before) * help texts have been reworked, to make them - sometimes smaller - sometimes describe the options better - more often present themselves in a nicer format * all long help texts are now created with BUSYBOX_CMD_HELP_ macros, no more 'static const __maybe_unused char cmd_foobar_help[]' * made sure the long help texts starts uppercase * because cmdtp->name and cmdtp->opts together provide the new usage, all "Usage: foobar" texts have been removed from the long help texts * BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this is nicer in the source code * BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself * made sure no line gets longer than 77 characters * delibertely renamed cmdtp->usage, so that we can get compile-time errors (e.g. in out-of-tree modules that use register_command() * the 'help' command can now always emit the usage, even without compiled long help texts * 'help -v' gives a list of commands with their short description, this is similar like the old "help" command before my patchset * 'help -a' gives out help of all commands Signed-off-by: Holger Schurig <holgerschurig@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/help.c')
-rw-r--r--commands/help.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/commands/help.c b/commands/help.c
index 7f31ce1..9c33807 100644
--- a/commands/help.c
+++ b/commands/help.c
@@ -42,7 +42,7 @@ static void list_group(int verbose, const char *grpname, uint32_t group)
}
}
if (verbose) {
- printf(" %-21s %s\n", cmdtp->name, cmdtp->usage);
+ printf(" %-21s %s\n", cmdtp->name, cmdtp->desc);
continue;
}
len = strlen(cmdtp->name);
@@ -67,8 +67,8 @@ static void list_commands(int verbose)
putchar('\n');
list_group(verbose, "Information", CMD_GRP_INFO);
list_group(verbose, "Boot", CMD_GRP_BOOT);
- list_group(verbose, "Environment", CMD_GRP_ENV);
list_group(verbose, "Partition", CMD_GRP_PART);
+ list_group(verbose, "Environment", CMD_GRP_ENV);
list_group(verbose, "File", CMD_GRP_FILE);
list_group(verbose, "Scripting", CMD_GRP_SCRIPT);
list_group(verbose, "Network", CMD_GRP_NET);
@@ -88,21 +88,31 @@ static void list_commands(int verbose)
static int do_help(int argc, char *argv[])
{
struct command *cmdtp;
- int opt, verbose = 0;
+ int opt, verbose = 0, all = 0;
- while ((opt = getopt(argc, argv, "v")) > 0) {
+ while ((opt = getopt(argc, argv, "va")) > 0) {
switch (opt) {
case 'v':
verbose = 1;
break;
+ case 'a':
+ all = 1;
+ break;
}
}
+ if (all) {
+ for_each_command(cmdtp)
+ barebox_cmd_usage(cmdtp);
+ return 0;
+ }
+
if (optind == argc) { /* show list of commands */
list_commands(verbose);
return 0;
}
+
/* command help (long version) */
if ((cmdtp = find_cmd(argv[optind])) != NULL) {
barebox_cmd_usage(cmdtp);
@@ -110,25 +120,30 @@ static int do_help(int argc, char *argv[])
} else {
printf ("Unknown command '%s' - try 'help'"
" without arguments for list of all"
- " known commands\n\n", argv[1]
+ " known commands\n\n", argv[optind]
);
return 1;
}
}
-static const __maybe_unused char cmd_help_help[] =
-"Show help information (for 'command')\n"
-"'help' prints online help for the monitor commands.\n\n"
-"Without arguments, it lists all all commands.\n\n"
-"To get detailed help information for specific commands you can type\n"
-"'help' with a command names as argument.\n";
+
+BAREBOX_CMD_HELP_START(help)
+BAREBOX_CMD_HELP_TEXT("Without arguments, lists all all commands. With an argument, print help")
+BAREBOX_CMD_HELP_TEXT("about the specified command. If the argument is 'all', then output help")
+BAREBOX_CMD_HELP_TEXT("for all commands.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-a", "output help on all commands")
+BAREBOX_CMD_HELP_OPT ("-v", "verbose")
+BAREBOX_CMD_HELP_END
static const char *help_aliases[] = { "?", NULL};
BAREBOX_CMD_START(help)
.cmd = do_help,
.aliases = help_aliases,
- .usage = "print online help",
+ BAREBOX_CMD_DESC("print online help")
+ BAREBOX_CMD_OPTS("[-v] [COMMAND]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_HELP(cmd_help_help)
BAREBOX_CMD_COMPLETE(command_complete)