Merge branch 'pr-359' into dev
This commit is contained in:
commit
44322a74a7
|
@ -17,7 +17,7 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use log::{error, warn};
|
use log::{error, info, warn};
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
use serde_yaml::{Mapping, Value};
|
use serde_yaml::{Mapping, Value};
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
|
@ -126,11 +126,12 @@ impl super::Extension for ShellExtension {
|
||||||
warn!("No 'cmd' parameter specified for shell variable");
|
warn!("No 'cmd' parameter specified for shell variable");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let cmd = cmd.unwrap().as_str().unwrap();
|
|
||||||
|
let original_cmd = cmd.unwrap().as_str().unwrap();
|
||||||
|
|
||||||
// Render positional parameters in args
|
// Render positional parameters in args
|
||||||
let cmd = POS_ARG_REGEX
|
let cmd = POS_ARG_REGEX
|
||||||
.replace_all(&cmd, |caps: &Captures| {
|
.replace_all(&original_cmd, |caps: &Captures| {
|
||||||
let position_str = caps.name("pos").unwrap().as_str();
|
let position_str = caps.name("pos").unwrap().as_str();
|
||||||
let position = position_str.parse::<i32>().unwrap_or(-1);
|
let position = position_str.parse::<i32>().unwrap_or(-1);
|
||||||
if position >= 0 && position < args.len() as i32 {
|
if position >= 0 && position < args.len() as i32 {
|
||||||
|
@ -171,6 +172,22 @@ impl super::Extension for ShellExtension {
|
||||||
warn!("Shell command reported error: \n{}", error_str);
|
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 {
|
||||||
|
info!(
|
||||||
|
"debug for shell cmd '{}', exit_status '{}', stdout '{}', stderr '{}'",
|
||||||
|
original_cmd, output.status, output_str, error_str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// If specified, trim the output
|
// If specified, trim the output
|
||||||
let trim_opt = params.get(&Value::from("trim"));
|
let trim_opt = params.get(&Value::from("trim"));
|
||||||
let should_trim = if let Some(value) = trim_opt {
|
let should_trim = if let Some(value) = trim_opt {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user