Skip to content

Commit f114030

Browse files
ikegami-tigaw
authored andcommitted
plugin: translate -h into commands
As the help short option parsed -h by argconfig so follow plugin also. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 5ced5c0 commit f114030

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

plugin.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
144144
struct command **cmd = plugin->commands;
145145
struct command *cr = NULL;
146146
bool cr_valid = false;
147+
int dash_count = 0;
147148

148149
if (!argc) {
149150
general_help(plugin);
@@ -156,11 +157,14 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
156157
sprintf(use, "%s %s %s <device> [OPTIONS]", prog->name, plugin->name, str);
157158
argconfig_append_usage(use);
158159

159-
/* translate --help and --version into commands */
160-
while (*str == '-')
161-
str++;
160+
/* translate --help, -h and --version into commands */
161+
while (str[dash_count] == '-')
162+
dash_count++;
162163

163-
if (!strcmp(str, "help"))
164+
if (dash_count)
165+
str += dash_count;
166+
167+
if (!strcmp(str, "help") || (dash_count == 1 && !strcmp(str, "h")))
164168
return help(argc, argv, plugin);
165169
if (!strcmp(str, "version"))
166170
return version_cmd(plugin);

0 commit comments

Comments
 (0)