diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-14 18:28:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-16 15:12:07 +0000 |
commit | 589986012c4b3ab68e299a2eadca18f90080113b (patch) | |
tree | f29a53b04a1950cdddae69344bccb3f0146fa728 /plugin.c | |
parent | Releasing debian version 1.16-4. (diff) | |
download | nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.tar.xz nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.zip |
Merging upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugin.c')
-rw-r--r-- | plugin.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -121,12 +121,13 @@ void general_help(struct plugin *plugin) int handle_plugin(int argc, char **argv, struct plugin *plugin) { - unsigned i = 0; char *str = argv[0]; char use[0x100]; - struct plugin *extension; struct program *prog = plugin->parent; + struct command **cmd = plugin->commands; + struct command *cr = NULL; + bool cr_valid = false; if (!argc) { general_help(plugin); @@ -148,18 +149,29 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin) if (!strcmp(str, "version")) return version(plugin); - for (; plugin->commands[i]; i++) { - struct command *cmd = plugin->commands[i]; - - if (strcmp(str, cmd->name)) - if (!cmd->alias || (cmd->alias && strcmp(str, cmd->alias))) - continue; + while (*cmd) { + if (!strcmp(str, (*cmd)->name) || + ((*cmd)->alias && !strcmp(str, (*cmd)->alias))) + return (*cmd)->fn(argc, argv, *cmd, plugin); + if (!strncmp(str, (*cmd)->name, strlen(str))) { + if (cr) { + cr_valid = false; + } else { + cr = *cmd; + cr_valid = true; + } + } + cmd++; + } - return (cmd->fn(argc, argv, cmd, plugin)); + if (cr && cr_valid) { + sprintf(use, "%s %s <device> [OPTIONS]", prog->name, cr->name); + argconfig_append_usage(use); + return cr->fn(argc, argv, cr, plugin); } /* Check extensions only if this is running the built-in plugin */ - if (plugin->name) { + if (plugin->name) { printf("ERROR: Invalid sub-command '%s' for plugin %s\n", str, plugin->name); return -ENOTTY; } |