Format source code
This commit is contained in:
parent
cc72f10398
commit
0ead01d5d6
|
@ -66,7 +66,7 @@ impl super::Extension for RandomExtension {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
error!("Could not select a random choice.");
|
error!("Could not select a random choice.");
|
||||||
return Err(super::ExtensionError::Internal)
|
return Err(super::ExtensionError::Internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,9 @@ mod tests {
|
||||||
params.insert(Value::from("choices"), Value::from(choices.clone()));
|
params.insert(Value::from("choices"), Value::from(choices.clone()));
|
||||||
|
|
||||||
let extension = RandomExtension::new();
|
let extension = RandomExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
|
@ -106,7 +108,9 @@ mod tests {
|
||||||
params.insert(Value::from("choices"), Value::from(choices.clone()));
|
params.insert(Value::from("choices"), Value::from(choices.clone()));
|
||||||
|
|
||||||
let extension = RandomExtension::new();
|
let extension = RandomExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec!["test".to_owned()], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec!["test".to_owned()], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
|
|
|
@ -121,12 +121,8 @@ impl Shell {
|
||||||
|
|
||||||
fn get_arg_regex(&self) -> &Regex {
|
fn get_arg_regex(&self) -> &Regex {
|
||||||
let regex = match self {
|
let regex = match self {
|
||||||
Shell::Cmd | Shell::Powershell => {
|
Shell::Cmd | Shell::Powershell => &*WIN_POS_ARG_REGEX,
|
||||||
&*WIN_POS_ARG_REGEX
|
_ => &*UNIX_POS_ARG_REGEX,
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
&*UNIX_POS_ARG_REGEX
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
regex
|
regex
|
||||||
}
|
}
|
||||||
|
@ -196,17 +192,18 @@ impl super::Extension for ShellExtension {
|
||||||
|
|
||||||
// Render positional parameters in args
|
// Render positional parameters in args
|
||||||
let cmd = if inject_args {
|
let cmd = if inject_args {
|
||||||
shell.get_arg_regex()
|
shell
|
||||||
.replace_all(&original_cmd, |caps: &Captures| {
|
.get_arg_regex()
|
||||||
let position_str = caps.name("pos").unwrap().as_str();
|
.replace_all(&original_cmd, |caps: &Captures| {
|
||||||
let position = position_str.parse::<i32>().unwrap_or(-1);
|
let position_str = caps.name("pos").unwrap().as_str();
|
||||||
if position >= 0 && position < args.len() as i32 {
|
let position = position_str.parse::<i32>().unwrap_or(-1);
|
||||||
args[position as usize].to_owned()
|
if position >= 0 && position < args.len() as i32 {
|
||||||
} else {
|
args[position as usize].to_owned()
|
||||||
"".to_owned()
|
} else {
|
||||||
}
|
"".to_owned()
|
||||||
})
|
}
|
||||||
.to_string()
|
})
|
||||||
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
original_cmd.to_owned()
|
original_cmd.to_owned()
|
||||||
};
|
};
|
||||||
|
@ -279,7 +276,9 @@ mod tests {
|
||||||
params.insert(Value::from("trim"), Value::from(false));
|
params.insert(Value::from("trim"), Value::from(false));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
|
@ -302,7 +301,9 @@ mod tests {
|
||||||
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
params.insert(Value::from("cmd"), Value::from("echo \"hello world\""));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -320,7 +321,9 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -336,7 +339,9 @@ mod tests {
|
||||||
params.insert(Value::from("trim"), Value::from("error"));
|
params.insert(Value::from("trim"), Value::from("error"));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -353,7 +358,9 @@ mod tests {
|
||||||
params.insert(Value::from("trim"), Value::from(true));
|
params.insert(Value::from("trim"), Value::from(true));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec![], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec![], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -370,7 +377,9 @@ mod tests {
|
||||||
params.insert(Value::from("inject_args"), Value::from(true));
|
params.insert(Value::from("inject_args"), Value::from(true));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
|
@ -381,14 +390,22 @@ mod tests {
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn test_shell_no_default_inject_args_unix() {
|
fn test_shell_no_default_inject_args_unix() {
|
||||||
let mut params = Mapping::new();
|
let mut params = Mapping::new();
|
||||||
params.insert(Value::from("cmd"), Value::from("echo 'hey friend' | awk '{ print $2 }'"));
|
params.insert(
|
||||||
|
Value::from("cmd"),
|
||||||
|
Value::from("echo 'hey friend' | awk '{ print $2 }'"),
|
||||||
|
);
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
assert_eq!(output.unwrap(), ExtensionResult::Single("friend".to_owned()));
|
assert_eq!(
|
||||||
|
output.unwrap(),
|
||||||
|
ExtensionResult::Single("friend".to_owned())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -399,7 +416,9 @@ mod tests {
|
||||||
params.insert(Value::from("inject_args"), Value::from(true));
|
params.insert(Value::from("inject_args"), Value::from(true));
|
||||||
|
|
||||||
let extension = ShellExtension::new();
|
let extension = ShellExtension::new();
|
||||||
let output = extension.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new()).unwrap();
|
let output = extension
|
||||||
|
.calculate(¶ms, &vec!["hello".to_owned()], &HashMap::new())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(output.is_some());
|
assert!(output.is_some());
|
||||||
|
|
||||||
|
|
|
@ -199,11 +199,8 @@ impl super::Renderer for DefaultRenderer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => return RenderResult::Error,
|
||||||
return RenderResult::Error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
"No extension found for variable type: {}",
|
"No extension found for variable type: {}",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user