Set trim option default to true in shell extension. Fix #272
This commit is contained in:
parent
8e563b6327
commit
a37c588e26
|
@ -143,14 +143,16 @@ impl super::Extension for ShellExtension {
|
||||||
|
|
||||||
// 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"));
|
||||||
if let Some(value) = trim_opt {
|
let should_trim = if let Some(value) = trim_opt {
|
||||||
let val = value.as_bool();
|
let val = value.as_bool();
|
||||||
if let Some(val) = val {
|
val.unwrap_or(true)
|
||||||
if val {
|
}else{
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
if should_trim {
|
||||||
output_str = output_str.trim().to_owned()
|
output_str = output_str.trim().to_owned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(output_str)
|
Some(output_str)
|
||||||
}
|
}
|
||||||
|
@ -168,9 +170,10 @@ mod tests {
|
||||||
use crate::extension::Extension;
|
use crate::extension::Extension;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shell_basic() {
|
fn test_shell_not_trimmed() {
|
||||||
let mut params = Mapping::new();
|
let mut params = Mapping::new();
|
||||||
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
||||||
|
params.insert(Value::from("trim"), Value::from(false));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![]);
|
let output = extension.calculate(¶ms, &vec![]);
|
||||||
|
@ -185,10 +188,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shell_trimmed() {
|
fn test_shell_basic() {
|
||||||
let mut params = Mapping::new();
|
let mut params = Mapping::new();
|
||||||
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
||||||
params.insert(Value::from("trim"), Value::from(true));
|
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![]);
|
let output = extension.calculate(¶ms, &vec![]);
|
||||||
|
@ -205,8 +207,6 @@ mod tests {
|
||||||
Value::from("echo \" hello world \""),
|
Value::from("echo \" hello world \""),
|
||||||
);
|
);
|
||||||
|
|
||||||
params.insert(Value::from("trim"), Value::from(true));
|
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![]);
|
let output = extension.calculate(¶ms, &vec![]);
|
||||||
|
|
||||||
|
@ -224,11 +224,7 @@ mod tests {
|
||||||
let output = extension.calculate(¶ms, &vec![]);
|
let output = extension.calculate(¶ms, &vec![]);
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
if cfg!(target_os = "windows") {
|
assert_eq!(output.unwrap(), "hello world");
|
||||||
assert_eq!(output.unwrap(), "hello world\r\n");
|
|
||||||
} else {
|
|
||||||
assert_eq!(output.unwrap(), "hello world\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -256,7 +252,7 @@ mod tests {
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
assert_eq!(output.unwrap(), "hello\n");
|
assert_eq!(output.unwrap(), "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -270,6 +266,6 @@ mod tests {
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
assert_eq!(output.unwrap(), "hello\r\n");
|
assert_eq!(output.unwrap(), "hello");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user