diff 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
line wrap: on
line diff
--- a/cmd.c	Tue Nov 28 16:48:45 2017 +0100
+++ b/cmd.c	Tue Nov 28 17:16:24 2017 +0100
@@ -1205,24 +1205,27 @@
 		return (CMD_USAGE);
 	}
 
-	pager = pager_create(STDOUT_FILENO);
 	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)) {
-				pager_printf(pager, "%s\n", cmd->usage);
+				if (io_printf("usage: %s\n", cmd->usage) ==
+				    IO_SIGNAL) {
+					retval = CMD_SIGNAL;
+				}
 				break;
 			}
 		}
 	} else {
-		printf("Commands:\n");
+		pager = pager_create(STDOUT_FILENO);
+		pager_printf(pager, "Commands:\n");
 		for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
 			pager_printf(pager, "%-2s %-16s %s\n", cmd->abbrev_cmd,
 			    cmd->full_cmd, cmd->description);
 		}
+		retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL;
+		pager_destroy(pager);
 	}
-	retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL;
-	pager_destroy(pager);
 
 	return (retval);
 }