diff --git a/nvme.c b/nvme.c index 636ca82ecc..8f16317608 100644 --- a/nvme.c +++ b/nvme.c @@ -10911,14 +10911,14 @@ int main(int argc, char **argv) nvme.extensions->parent = &nvme; if (argc < 2) { - general_help(&builtin); + general_help(&builtin, NULL); return 0; } setlocale(LC_ALL, ""); err = handle_plugin(argc - 1, &argv[1], nvme.extensions); if (err == -ENOTTY) - general_help(&builtin); + general_help(&builtin, NULL); return err ? 1 : 0; } diff --git a/plugin.c b/plugin.c index a5cb4f995a..0b94f3c9f8 100644 --- a/plugin.c +++ b/plugin.c @@ -34,7 +34,7 @@ static int help(int argc, char **argv, struct plugin *plugin) int i; if (argc == 1) { - general_help(plugin); + general_help(plugin, NULL); return 0; } @@ -52,6 +52,9 @@ static int help(int argc, char **argv, struct plugin *plugin) if (execlp("man", "man", man, (char *)NULL)) perror(argv[1]); } + + general_help(plugin, str); + return 0; } @@ -65,7 +68,7 @@ static void usage_cmd(struct plugin *plugin) printf("usage: %s %s\n", prog->name, prog->usage); } -void general_help(struct plugin *plugin) +void general_help(struct plugin *plugin, char *str) { struct program *prog = plugin->parent; struct plugin *extension; @@ -88,6 +91,8 @@ void general_help(struct plugin *plugin) } printf("\nThe following are all implemented sub-commands:\n"); + if (str) + printf("Note: Only sub-commands including %s\n", str); /* * iterate through all commands to get maximum length @@ -100,12 +105,16 @@ void general_help(struct plugin *plugin) } i = 0; - for (; plugin->commands[i]; i++) - printf(" %-*s %s\n", padding, plugin->commands[i]->name, - plugin->commands[i]->help); + for (; plugin->commands[i]; i++) { + if (!str || strstr(plugin->commands[i]->name, str)) + printf(" %-*s %s\n", padding, plugin->commands[i]->name, + plugin->commands[i]->help); + } - printf(" %-*s %s\n", padding, "version", "Shows the program version"); - printf(" %-*s %s\n", padding, "help", "Display this help"); + if (!str || strstr("version", str)) + printf(" %-*s %s\n", padding, "version", "Shows the program version"); + if (!str || strstr("help", str)) + printf(" %-*s %s\n", padding, "help", "Display this help"); printf("\n"); if (plugin->name) @@ -127,8 +136,12 @@ void general_help(struct plugin *plugin) return; printf("\nThe following are all installed plugin extensions:\n"); + if (str) + printf("Note: Only extensions including %s\n", str); + while (extension) { - printf(" %-*s %s\n", 15, extension->name, extension->desc); + if (!str || strstr(extension->name, str)) + printf(" %-*s %s\n", 15, extension->name, extension->desc); extension = extension->next; } printf("\nSee '%s help' for more information on a plugin\n", @@ -146,7 +159,7 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin) bool cr_valid = false; if (!argc) { - general_help(plugin); + general_help(plugin, NULL); return 0; } diff --git a/plugin.h b/plugin.h index 03bd95a7bd..0262efe1a8 100644 --- a/plugin.h +++ b/plugin.h @@ -31,7 +31,7 @@ struct command { char *alias; }; -void general_help(struct plugin *plugin); +void general_help(struct plugin *plugin, char *str); int handle_plugin(int argc, char **argv, struct plugin *plugin); #endif