From 8030cf16ca676e20840618f1f623f5caf43dcd3c Mon Sep 17 00:00:00 2001 From: Ralph Caraveo Date: Thu, 9 Jul 2020 20:45:17 -0700 Subject: [PATCH] Adds a debug option for espanso when executing shell commands for greater context --- src/extension/shell.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/extension/shell.rs b/src/extension/shell.rs index f1b9da4..82186ea 100644 --- a/src/extension/shell.rs +++ b/src/extension/shell.rs @@ -123,7 +123,7 @@ impl super::Extension for ShellExtension { fn calculate(&self, params: &Mapping, args: &Vec) -> Option { let cmd = params.get(&Value::from("cmd")); if cmd.is_none() { - warn!("No 'cmd' parameter specified for shell variable"); + warn!("No 'cmd' parameter specified for shell `iable"); return None; } let cmd = cmd.unwrap().as_str().unwrap(); @@ -171,6 +171,19 @@ impl super::Extension for ShellExtension { warn!("Shell command reported error: \n{}", error_str); } + // Check if debug flag set, provide additional context when an error occurs. + let debug_opt = params.get(&Value::from("debug")); + let with_debug = if let Some(value) = debug_opt { + let val = value.as_bool(); + val.unwrap_or(false) + }else{ + false + }; + + if with_debug { + error!("debug for shell cmd '{}', exit_status '{}', stdout '{}', stderr '{}'", cmd, output.status, output_str, error_str); + } + // If specified, trim the output let trim_opt = params.get(&Value::from("trim")); let should_trim = if let Some(value) = trim_opt {