projects/pwm

changeset 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 Nov 28 17:16:24 2017 +0100 (2017-11-28)
parents 9be355e742e5
children fa93d2ff9c62
files cmd.c
line diff
     1.1 --- a/cmd.c	Tue Nov 28 16:48:45 2017 +0100
     1.2 +++ b/cmd.c	Tue Nov 28 17:16:24 2017 +0100
     1.3 @@ -1205,24 +1205,27 @@
     1.4  		return (CMD_USAGE);
     1.5  	}
     1.6  
     1.7 -	pager = pager_create(STDOUT_FILENO);
     1.8  	if (argc == 2) {
     1.9  		for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
    1.10  			if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) ||
    1.11  			    (strcmp(argv[1], cmd->full_cmd) == 0)) {
    1.12 -				pager_printf(pager, "%s\n", cmd->usage);
    1.13 +				if (io_printf("usage: %s\n", cmd->usage) ==
    1.14 +				    IO_SIGNAL) {
    1.15 +					retval = CMD_SIGNAL;
    1.16 +				}
    1.17  				break;
    1.18  			}
    1.19  		}
    1.20  	} else {
    1.21 -		printf("Commands:\n");
    1.22 +		pager = pager_create(STDOUT_FILENO);
    1.23 +		pager_printf(pager, "Commands:\n");
    1.24  		for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
    1.25  			pager_printf(pager, "%-2s %-16s %s\n", cmd->abbrev_cmd,
    1.26  			    cmd->full_cmd, cmd->description);
    1.27  		}
    1.28 +		retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL;
    1.29 +		pager_destroy(pager);
    1.30  	}
    1.31 -	retval = (pager_show(pager) != IO_SIGNAL) ? CMD_OK : CMD_SIGNAL;
    1.32 -	pager_destroy(pager);
    1.33  
    1.34  	return (retval);
    1.35  }