Adds a debug option for espanso when executing shell commands for greater context

This commit is contained in:
Ralph Caraveo 2020-07-09 20:45:17 -07:00
parent c12eae9d0a
commit 8030cf16ca

View File

@ -123,7 +123,7 @@ impl super::Extension for ShellExtension {
fn calculate(&self, params: &Mapping, args: &Vec<String>) -> Option<String> {
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 {