Skip to content

Commit aa3b884

Browse files
ikegami-tigaw
authored andcommitted
nvme: add general_help str parameter to filter sub-commands
If any string specified by the help command then listed only commands including the string. This is to make easier to guide the commands. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 3be8502 commit aa3b884

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

nvme.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10924,14 +10924,14 @@ int main(int argc, char **argv)
1092410924

1092510925
nvme.extensions->parent = &nvme;
1092610926
if (argc < 2) {
10927-
general_help(&builtin);
10927+
general_help(&builtin, NULL);
1092810928
return 0;
1092910929
}
1093010930
setlocale(LC_ALL, "");
1093110931

1093210932
err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
1093310933
if (err == -ENOTTY)
10934-
general_help(&builtin);
10934+
general_help(&builtin, NULL);
1093510935

1093610936
return err ? 1 : 0;
1093710937
}

plugin.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int help(int argc, char **argv, struct plugin *plugin)
3434
int i;
3535

3636
if (argc == 1) {
37-
general_help(plugin);
37+
general_help(plugin, NULL);
3838
return 0;
3939
}
4040

@@ -52,6 +52,9 @@ static int help(int argc, char **argv, struct plugin *plugin)
5252
if (execlp("man", "man", man, (char *)NULL))
5353
perror(argv[1]);
5454
}
55+
56+
general_help(plugin, str);
57+
5558
return 0;
5659
}
5760

@@ -65,7 +68,7 @@ static void usage_cmd(struct plugin *plugin)
6568
printf("usage: %s %s\n", prog->name, prog->usage);
6669
}
6770

68-
void general_help(struct plugin *plugin)
71+
void general_help(struct plugin *plugin, char *str)
6972
{
7073
struct program *prog = plugin->parent;
7174
struct plugin *extension;
@@ -88,6 +91,8 @@ void general_help(struct plugin *plugin)
8891
}
8992

9093
printf("\nThe following are all implemented sub-commands:\n");
94+
if (str)
95+
printf("Note: Only sub-commands including %s\n", str);
9196

9297
/*
9398
* iterate through all commands to get maximum length
@@ -100,12 +105,16 @@ void general_help(struct plugin *plugin)
100105
}
101106

102107
i = 0;
103-
for (; plugin->commands[i]; i++)
104-
printf(" %-*s %s\n", padding, plugin->commands[i]->name,
105-
plugin->commands[i]->help);
108+
for (; plugin->commands[i]; i++) {
109+
if (!str || strstr(plugin->commands[i]->name, str))
110+
printf(" %-*s %s\n", padding, plugin->commands[i]->name,
111+
plugin->commands[i]->help);
112+
}
106113

107-
printf(" %-*s %s\n", padding, "version", "Shows the program version");
108-
printf(" %-*s %s\n", padding, "help", "Display this help");
114+
if (!str || strstr("version", str))
115+
printf(" %-*s %s\n", padding, "version", "Shows the program version");
116+
if (!str || strstr("help", str))
117+
printf(" %-*s %s\n", padding, "help", "Display this help");
109118
printf("\n");
110119

111120
if (plugin->name)
@@ -127,8 +136,12 @@ void general_help(struct plugin *plugin)
127136
return;
128137

129138
printf("\nThe following are all installed plugin extensions:\n");
139+
if (str)
140+
printf("Note: Only extensions including %s\n", str);
141+
130142
while (extension) {
131-
printf(" %-*s %s\n", 15, extension->name, extension->desc);
143+
if (!str || strstr(extension->name, str))
144+
printf(" %-*s %s\n", 15, extension->name, extension->desc);
132145
extension = extension->next;
133146
}
134147
printf("\nSee '%s <plugin> help' for more information on a plugin\n",
@@ -147,7 +160,7 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
147160
int dash_count = 0;
148161

149162
if (!argc) {
150-
general_help(plugin);
163+
general_help(plugin, NULL);
151164
return 0;
152165
}
153166

plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct command {
3131
char *alias;
3232
};
3333

34-
void general_help(struct plugin *plugin);
34+
void general_help(struct plugin *plugin, char *str);
3535
int handle_plugin(int argc, char **argv, struct plugin *plugin);
3636

3737
#endif

0 commit comments

Comments
 (0)