]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Execute plugin when name is combined with command
authorKeith Busch <keith.busch@intel.com>
Wed, 8 Jun 2016 18:13:55 +0000 (12:13 -0600)
committerKeith Busch <keith.busch@intel.com>
Wed, 8 Jun 2016 23:27:05 +0000 (17:27 -0600)
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 <keith.busch@intel.com>
plugin.c

index 1b52a00b29fc2170ac2a2577281c05d439b3cd92..f5ecfb574ccd33471730bfb75c0905931355b799 100644 (file)
--- 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;