opensc-explorer: allow arguments for 'help'

When arguments are given, compare them like ambguous_match() does,
and show the matching ones only.

Add documentation of the 'help' command to the manual page.

In main loop on multiple matches, show help on matching commands only.
This commit is contained in:
Peter Marschall 2018-07-14 21:46:41 +02:00 committed by Frank Morgner
parent c817be8faa
commit c9db3f7385
2 changed files with 34 additions and 9 deletions

View File

@ -392,6 +392,22 @@
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>help</command>
<arg choice="opt"><replaceable>pattern</replaceable></arg>
</term>
<listitem>
<para>
Display the list of available commands, their options
and parameters together with a short help text.
If <replaceable>pattern</replaceable> is given,
the commands shown are limited to those matching
<replaceable>pattern</replaceable>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>info</command>

View File

@ -1986,17 +1986,26 @@ static int do_help(int argc, char **argv)
{
struct command *cmd;
if (argc)
return usage(do_help);
printf("%s commands:\n", (argc) ? "Matching" : "Supported");
printf("Supported commands:\n");
for (cmd = cmds; cmd->name; cmd++) {
int len = strlen(cmd->name) + strlen(cmd->args);
printf(" %s %s%*s %s\n",
cmd->name, cmd->args,
(len > 40) ? 0 : (40 - len), "",
cmd->help);
int i;
int match = 0;
for (i = 0; i < argc; i++) {
if (strncmp(cmd->name, argv[i], strlen(argv[i])) == 0)
match++;
}
if (match || !argc) {
int len = strlen(cmd->name) + strlen(cmd->args);
printf(" %s %s%*s %s\n",
cmd->name, cmd->args,
(len > 40) ? 0 : (40 - len), "",
cmd->help);
}
}
return 0;
}
@ -2210,7 +2219,7 @@ int main(int argc, char *argv[])
if (cmd == NULL) {
fprintf(stderr, "%s command: %s\n",
(multiple) ? "Ambiguous" : "Unknown", cargv[0]);
do_help(0, NULL);
do_help((multiple) ? 1 : 0, cargv);
} else {
cmd->func(cargc-1, cargv+1);
}