From: Keith Busch Date: Wed, 8 Jun 2016 18:13:55 +0000 (-0600) Subject: Execute plugin when name is combined with command X-Git-Tag: v0.8~15 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=04eb06162a2e21111f27b9140c57e67aa452b465;p=users%2Fsagi%2Fnvme-cli.git Execute plugin when name is combined with command Let a user specify plug-in sub commands in the same string. For example, this patch will have the following two mean the same thing: # nvme intel id-ctrl # nvme intel-id-ctrl Signed-off-by: Keith Busch --- diff --git a/plugin.c b/plugin.c index 1b52a00b..f5ecfb57 100644 --- a/plugin.c +++ b/plugin.c @@ -142,11 +142,17 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin) extension = plugin->next; while (extension) { - if (strcmp(str, extension->name)) { - extension = extension->next; - continue; + if (!strcmp(str, extension->name)) + return handle_plugin(argc - 1, &argv[1], extension); + + /* If the command is executed with the extension name and + * command together ("plugin-command"), run the plug in */ + if (!strncmp(str, extension->name, strlen(extension->name))) { + argv[0] += strlen(extension->name); + while (*argv[0] == '-') + argv[0]++; + return handle_plugin(argc, &argv[0], extension); } - return handle_plugin(argc - 1, &argv[1], extension); extension = extension->next; } return -1;