From ab23d0bb3f66cfb7a97a8aa6b8007687ed7a6925 Mon Sep 17 00:00:00 2001 From: Holger Schurig Date: Tue, 13 May 2014 16:14:05 +0200 Subject: commands: group 'help' output The old output of "help" was just producing a long list, that usually scrolled of the screen (even on a X11 terminal). This list is more compact, and also sorted by groups. The old output format (plus grouping) is now available with 'help -v'. Example: Information commands: ?, devinfo, help, iomem, meminfo, version Boot commands: boot, bootm, go, loadb, loads, loadx, loady, saves, uimage ... Signed-off-by: Holger Schurig Signed-off-by: Sascha Hauer --- commands/help.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 13 deletions(-) (limited to 'commands/help.c') diff --git a/commands/help.c b/commands/help.c index a12d9c3547..7f31ce1f5d 100644 --- a/commands/help.c +++ b/commands/help.c @@ -19,8 +19,68 @@ #include #include +#include #include + +static void list_group(int verbose, const char *grpname, uint32_t group) +{ + struct command *cmdtp; + bool first = true; + int pos = 0; + int len; + + for_each_command(cmdtp) { + if (cmdtp->group != group) + continue; + if (first) { + first = false; + printf("%s commands:\n", grpname); + if (!verbose) { + printf(" "); + pos = 2; + } + } + if (verbose) { + printf(" %-21s %s\n", cmdtp->name, cmdtp->usage); + continue; + } + len = strlen(cmdtp->name); + if (pos + len + 2 > 77) { + printf("\n %s", cmdtp->name); + pos = len + 2; + } else { + if (pos != 2) { + printf(", "); + pos += 2; + } + printf(cmdtp->name); + pos += len; + } + } + if (!first) + printf("\n"); +} + +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, "File", CMD_GRP_FILE); + list_group(verbose, "Scripting", CMD_GRP_SCRIPT); + list_group(verbose, "Network", CMD_GRP_NET); + list_group(verbose, "Console", CMD_GRP_CONSOLE); + list_group(verbose, "Memory", CMD_GRP_MEM); + list_group(verbose, "Hardware manipulation", CMD_GRP_HWMANIP); + list_group(verbose, "Miscellaneous", CMD_GRP_MISC); + list_group(verbose, "Ungrouped", 0); + printf("Use 'help COMMAND' for more details.\n\n"); +} + + /* * Use puts() instead of printf() to avoid printf buffer overflow * for long help messages @@ -28,23 +88,23 @@ static int do_help(int argc, char *argv[]) { struct command *cmdtp; - int max_length = 0; - - if (argc == 1) { /* show list of commands */ - for_each_command(cmdtp) - if(strlen(cmdtp->name) > max_length) - max_length = strlen(cmdtp->name); + int opt, verbose = 0; - for_each_command(cmdtp) { - if (!cmdtp->usage) - continue; - printf("%*s - %s\n", max_length, cmdtp->name, cmdtp->usage); + while ((opt = getopt(argc, argv, "v")) > 0) { + switch (opt) { + case 'v': + verbose = 1; + break; } + } + + if (optind == argc) { /* show list of commands */ + list_commands(verbose); return 0; } /* command help (long version) */ - if ((cmdtp = find_cmd(argv[1])) != NULL) { + if ((cmdtp = find_cmd(argv[optind])) != NULL) { barebox_cmd_usage(cmdtp); return 0; } else { @@ -59,9 +119,9 @@ static int do_help(int argc, char *argv[]) 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 prints a short usage message for all 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 one or more command names as arguments.\n"; +"'help' with a command names as argument.\n"; static const char *help_aliases[] = { "?", NULL}; @@ -69,6 +129,7 @@ BAREBOX_CMD_START(help) .cmd = do_help, .aliases = help_aliases, .usage = "print online help", + BAREBOX_CMD_GROUP(CMD_GRP_INFO) BAREBOX_CMD_HELP(cmd_help_help) BAREBOX_CMD_COMPLETE(command_complete) BAREBOX_CMD_END -- cgit v1.2.3