Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
31 changes: 22 additions & 9 deletions plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 <plugin> help' for more information on a plugin\n",
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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