From 03d173cbd8e72c356512a0e19e356b07d518627a Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 25 Aug 2021 08:51:55 +0000 Subject: Validate command argument types (string or command list) and give more useful error messages. --- cmd-run-shell.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'cmd-run-shell.c') diff --git a/cmd-run-shell.c b/cmd-run-shell.c index f23a8ec3..662312fb 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -30,7 +30,10 @@ * Runs a command without a window. */ -static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *); +static enum args_parse_type cmd_run_shell_args_parse(struct args *, u_int, + char **); +static enum cmd_retval cmd_run_shell_exec(struct cmd *, + struct cmdq_item *); static void cmd_run_shell_timer(int, short, void *); static void cmd_run_shell_callback(struct job *); @@ -41,7 +44,7 @@ const struct cmd_entry cmd_run_shell_entry = { .name = "run-shell", .alias = "run", - .args = { "bd:Ct:", 0, 1, NULL }, + .args = { "bd:Ct:", 0, 1, cmd_run_shell_args_parse }, .usage = "[-bC] [-d delay] " CMD_TARGET_PANE_USAGE " [shell-command]", .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, @@ -62,6 +65,15 @@ struct cmd_run_shell_data { int flags; }; +static enum args_parse_type +cmd_run_shell_args_parse(struct args *args, __unused u_int idx, + __unused char **cause) +{ + if (args_has(args, 'C')) + return (ARGS_PARSE_COMMANDS_OR_STRING); + return (ARGS_PARSE_STRING); +} + static void cmd_run_shell_print(struct job *job, const char *msg) { -- cgit v1.2.3