summaryrefslogtreecommitdiffstats
path: root/plugin.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:27:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-16 15:11:56 +0000
commit6197903bd42478987516bc4cc3f0769488a37065 (patch)
tree508d399340039960289dd1d96696db7c56c22321 /plugin.c
parentAdding upstream version 1.16. (diff)
downloadnvme-cli-6197903bd42478987516bc4cc3f0769488a37065.tar.xz
nvme-cli-6197903bd42478987516bc4cc3f0769488a37065.zip
Adding upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--plugin.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/plugin.c b/plugin.c
index 78f03ab..fd8f67d 100644
--- a/plugin.c
+++ b/plugin.c
@@ -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;
}