# HG changeset patch # User Guido Berhoerster # Date 1502122607 -7200 # Node ID a01899a6e4bbe24c24499daafad30ac4e0bce7d4 # Parent cf81eb0c2d5a2b3eb1cbe37923d67c48ad28adbd Extend help command to show usage information for commands diff -r cf81eb0c2d5a -r a01899a6e4bb cmd.c --- a/cmd.c Mon Aug 07 16:59:47 2017 +0200 +++ b/cmd.c Mon Aug 07 18:16:47 2017 +0200 @@ -169,7 +169,7 @@ cmd_removegroup }, { "ch", "changepassword", "changepassword", "Change password", cmd_changepassword }, - { "h", "help", "help", "Show help text", cmd_help }, + { "h", "help", "help [command]", "Show help text", cmd_help }, { "w", "write", "write", "Write the database", cmd_write }, { "q", "quit", "quit", "Quit", cmd_quit }, { "Q", "Quit", "Quit", "Quit without checking", cmd_quit }, @@ -882,14 +882,24 @@ { struct cmd *cmd; - if (argc != 1) { + if (argc > 2) { return (CMD_USAGE); } - printf("Commands:\n"); - for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { - printf("%-2s %-16s %s\n", cmd->abbrev_cmd, cmd->full_cmd, - cmd->description); + if (argc == 2) { + for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { + if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) || + (strcmp(argv[1], cmd->full_cmd) == 0)) { + printf("%s\n", cmd->usage); + break; + } + } + } else { + printf("Commands:\n"); + for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { + printf("%-2s %-16s %s\n", cmd->abbrev_cmd, + cmd->full_cmd, cmd->description); + } } return (CMD_OK); diff -r cf81eb0c2d5a -r a01899a6e4bb pwm.1.xml --- a/pwm.1.xml Mon Aug 07 16:59:47 2017 +0200 +++ b/pwm.1.xml Mon Aug 07 18:16:47 2017 +0200 @@ -34,7 +34,7 @@ guido+pwm@berhoerster.name - 6 August, 2017 + 7 August, 2017 pwm @@ -458,12 +458,19 @@ help + + command + h + + command + - Display a list of all commands and a short help text. + Display a summary of all commands or usage information for + the specified command.