Mercurial > projects > pwm
diff cmd.c @ 14:a01899a6e4bb
Extend help command to show usage information for commands
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Mon, 07 Aug 2017 18:16:47 +0200 |
parents | cf81eb0c2d5a |
children | 3380c8fd9776 |
line wrap: on
line diff
--- 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);