Mercurial > projects > pwm
comparison cmd.c @ 32:b5ebed168e59
Only invoke pager in the help command for the summary of all commands
Display usage information for a single command directly and prefix it with
"usage:" like usage error messages.
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Tue, 28 Nov 2017 17:16:24 +0100 |
parents | 9be355e742e5 |
children | e027dd4409c7 |
comparison
equal
deleted
inserted
replaced
31:9be355e742e5 | 32:b5ebed168e59 |
---|---|
1203 | 1203 |
1204 if (argc > 2) { | 1204 if (argc > 2) { |
1205 return (CMD_USAGE); | 1205 return (CMD_USAGE); |
1206 } | 1206 } |
1207 | 1207 |
1208 pager = pager_create(STDOUT_FILENO); | |
1209 if (argc == 2) { | 1208 if (argc == 2) { |
1210 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { | 1209 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { |
1211 if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) || | 1210 if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) || |
1212 (strcmp(argv[1], cmd->full_cmd) == 0)) { | 1211 (strcmp(argv[1], cmd->full_cmd) == 0)) { |
1213 pager_printf(pager, "%s\n", cmd->usage); | 1212 if (io_printf("usage: %s\n", cmd->usage) == |
1213 IO_SIGNAL) { | |
1214 retval = CMD_SIGNAL; | |
1215 } | |
1214 break; | 1216 break; |
1215 } | 1217 } |
1216 } | 1218 } |
1217 } else { | 1219 } else { |
1218 printf("Commands:\n"); | 1220 pager = pager_create(STDOUT_FILENO); |
1221 pager_printf(pager, "Commands:\n"); | |
1219 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { | 1222 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { |
1220 pager_printf(pager, "%-2s %-16s %s\n", cmd->abbrev_cmd, | 1223 pager_printf(pager, "%-2s %-16s %s\n", cmd->abbrev_cmd, |
1221 cmd->full_cmd, cmd->description); | 1224 cmd->full_cmd, cmd->description); |
1222 } | 1225 } |
1223 } | 1226 retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL; |
1224 retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL; | 1227 pager_destroy(pager); |
1225 pager_destroy(pager); | 1228 } |
1226 | 1229 |
1227 return (retval); | 1230 return (retval); |
1228 } | 1231 } |
1229 | 1232 |
1230 static enum cmd_return | 1233 static enum cmd_return |