diff --git a/doc/tools/opensc-explorer.1.xml b/doc/tools/opensc-explorer.1.xml index 491bd81b..d924a934 100644 --- a/doc/tools/opensc-explorer.1.xml +++ b/doc/tools/opensc-explorer.1.xml @@ -392,6 +392,22 @@ + + + help + pattern + + + + Display the list of available commands, their options + and parameters together with a short help text. + If pattern is given, + the commands shown are limited to those matching + pattern. + + + + info diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c index dced848d..b8843463 100644 --- a/src/tools/opensc-explorer.c +++ b/src/tools/opensc-explorer.c @@ -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); }