summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2021-08-22 12:08:05 +0100
committerThomas Adam <thomas@xteddy.org>2021-08-22 12:08:05 +0100
commit324f87cf142fb1b7ed8cd738316bdb3f6fa7c1df (patch)
treec1116c69cccb5f9c2af6dec76886d05e0a6e093e /cmd.c
parent921991c98d6fd596c958b07b5f5aba7c434e8f9f (diff)
parent0084cbef5ad9f1f860b50fb7c485ac841817b3a8 (diff)
Merge branch 'obsd-master' into master
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/cmd.c b/cmd.c
index ffa496a5..e5765251 100644
--- a/cmd.c
+++ b/cmd.c
@@ -495,27 +495,26 @@ ambiguous:
/* Parse a single command from an argument vector. */
struct cmd *
-cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
+cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
+ char **cause)
{
const struct cmd_entry *entry;
- const char *name;
struct cmd *cmd;
struct args *args;
- if (argc == 0) {
+ if (count == 0 || values[0].type != ARGS_STRING) {
xasprintf(cause, "no command");
return (NULL);
}
- name = argv[0];
-
- entry = cmd_find(name, cause);
+ entry = cmd_find(values[0].string, cause);
if (entry == NULL)
return (NULL);
- cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
- args = args_parse(&entry->args, argc, argv);
- if (args == NULL)
- goto usage;
+ args = args_parse(&entry->args, values, count);
+ if (args == NULL) {
+ xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
+ return (NULL);
+ }
cmd = xcalloc(1, sizeof *cmd);
cmd->entry = entry;
@@ -526,12 +525,6 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
cmd->line = line;
return (cmd);
-
-usage:
- if (args != NULL)
- args_free(args);
- xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
- return (NULL);
}
/* Free a command. */