diff options
author | nicm <nicm> | 2021-08-25 08:51:55 +0000 |
---|---|---|
committer | nicm <nicm> | 2021-08-25 08:51:55 +0000 |
commit | 03d173cbd8e72c356512a0e19e356b07d518627a (patch) | |
tree | 3470ea9b0d06f58f84da38ba11c5bc9c015cb941 /cmd.c | |
parent | c6d6af49039d7fc3ec14c2240153226709497313 (diff) | |
download | rtmux-03d173cbd8e72c356512a0e19e356b07d518627a.tar.gz rtmux-03d173cbd8e72c356512a0e19e356b07d518627a.tar.bz2 rtmux-03d173cbd8e72c356512a0e19e356b07d518627a.zip |
Validate command argument types (string or command list) and give more
useful error messages.
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -502,6 +502,7 @@ cmd_parse(struct args_value *values, u_int count, const char *file, u_int line, const struct cmd_entry *entry; struct cmd *cmd; struct args *args; + char *error; if (count == 0 || values[0].type != ARGS_STRING) { xasprintf(cause, "no command"); @@ -511,11 +512,16 @@ cmd_parse(struct args_value *values, u_int count, const char *file, u_int line, if (entry == NULL) return (NULL); - args = args_parse(&entry->args, values, count); - if (args == NULL) { + args = args_parse(&entry->args, values, count, &error); + if (args == NULL && error == NULL) { xasprintf(cause, "usage: %s %s", entry->name, entry->usage); return (NULL); } + if (args == NULL) { + xasprintf(cause, "command %s: %s", entry->name, error); + free(error); + return (NULL); + } cmd = xcalloc(1, sizeof *cmd); cmd->entry = entry; |