projects/pwm

changeset 14:a01899a6e4bb

Extend help command to show usage information for commands
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon Aug 07 18:16:47 2017 +0200 (2017-08-07)
parents cf81eb0c2d5a
children 3380c8fd9776
files cmd.c pwm.1.xml
line diff
     1.1 --- a/cmd.c	Mon Aug 07 16:59:47 2017 +0200
     1.2 +++ b/cmd.c	Mon Aug 07 18:16:47 2017 +0200
     1.3 @@ -169,7 +169,7 @@
     1.4      cmd_removegroup },
     1.5      { "ch", "changepassword", "changepassword", "Change password",
     1.6      cmd_changepassword },
     1.7 -    { "h", "help", "help", "Show help text", cmd_help },
     1.8 +    { "h", "help", "help [command]", "Show help text", cmd_help },
     1.9      { "w", "write", "write", "Write the database", cmd_write },
    1.10      { "q", "quit", "quit", "Quit", cmd_quit },
    1.11      { "Q", "Quit", "Quit", "Quit without checking", cmd_quit },
    1.12 @@ -882,14 +882,24 @@
    1.13  {
    1.14  	struct cmd	*cmd;
    1.15  
    1.16 -	if (argc != 1) {
    1.17 +	if (argc > 2) {
    1.18  		return (CMD_USAGE);
    1.19  	}
    1.20  
    1.21 -	printf("Commands:\n");
    1.22 -	for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
    1.23 -		printf("%-2s %-16s %s\n", cmd->abbrev_cmd, cmd->full_cmd,
    1.24 -		    cmd->description);
    1.25 +	if (argc == 2) {
    1.26 +		for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
    1.27 +			if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) ||
    1.28 +			    (strcmp(argv[1], cmd->full_cmd) == 0)) {
    1.29 +				printf("%s\n", cmd->usage);
    1.30 +				break;
    1.31 +			}
    1.32 +		}
    1.33 +	} else {
    1.34 +		printf("Commands:\n");
    1.35 +		for (cmd = cmds; cmd->cmd_func != NULL; cmd++) {
    1.36 +			printf("%-2s %-16s %s\n", cmd->abbrev_cmd,
    1.37 +			    cmd->full_cmd, cmd->description);
    1.38 +		}
    1.39  	}
    1.40  
    1.41  	return (CMD_OK);
     2.1 --- a/pwm.1.xml	Mon Aug 07 16:59:47 2017 +0200
     2.2 +++ b/pwm.1.xml	Mon Aug 07 18:16:47 2017 +0200
     2.3 @@ -34,7 +34,7 @@
     2.4        <email>guido+pwm@berhoerster.name</email>
     2.5        <personblurb/>
     2.6      </author>
     2.7 -    <date>6 August, 2017</date>
     2.8 +    <date>7 August, 2017</date>
     2.9    </info>
    2.10    <refmeta>
    2.11      <refentrytitle>pwm</refentrytitle>
    2.12 @@ -458,12 +458,19 @@
    2.13            <listitem>
    2.14              <cmdsynopsis>
    2.15                <command>help</command>
    2.16 +              <arg choice="opt">
    2.17 +                <replaceable>command</replaceable>
    2.18 +              </arg>
    2.19              </cmdsynopsis>
    2.20              <cmdsynopsis>
    2.21                <command>h</command>
    2.22 +              <arg choice="opt">
    2.23 +                <replaceable>command</replaceable>
    2.24 +              </arg>
    2.25                <sbr/>
    2.26              </cmdsynopsis>
    2.27 -            <para>Display a list of all commands and a short help text.</para>
    2.28 +            <para>Display a summary of all commands or usage information for
    2.29 +            the specified <replaceable>command</replaceable>.</para>
    2.30            </listitem>
    2.31          </varlistentry>
    2.32          <varlistentry>