fix(render): fix warnings
This commit is contained in:
parent
71f0b575d3
commit
4b57dd04ca
|
@ -88,12 +88,12 @@ impl<'a> Extension for FormExtension<'a> {
|
|||
}
|
||||
|
||||
// TODO: test
|
||||
fn inject_scope(fields: &mut HashMap<String, Value>, scope: &HashMap<&str, ExtensionOutput>) -> () {
|
||||
for (_, value) in fields {
|
||||
fn inject_scope(fields: &mut HashMap<String, Value>, scope: &HashMap<&str, ExtensionOutput>) {
|
||||
for value in fields.values_mut() {
|
||||
if let Value::Object(field_options) = value {
|
||||
if let Some(Value::String(default_value)) = field_options.get_mut("default") {
|
||||
if VAR_REGEX.is_match(default_value) {
|
||||
match render_variables(&default_value, scope) {
|
||||
match render_variables(default_value, scope) {
|
||||
Ok(rendered) => *default_value = rendered,
|
||||
Err(err) => error!(
|
||||
"error while injecting variable in form default value: {}",
|
||||
|
@ -111,10 +111,3 @@ pub enum FormExtensionError {
|
|||
#[error("missing layout parameter")]
|
||||
MissingLayout,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// TODO: test
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ impl Extension for ScriptExtension {
|
|||
|
||||
let mut command = Command::new(&args[0]);
|
||||
command.env("CONFIG", self.config_path.to_string_lossy().to_string());
|
||||
for (key, value) in super::util::convert_to_env_variables(&scope) {
|
||||
for (key, value) in super::util::convert_to_env_variables(scope) {
|
||||
command.env(key, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,34 +43,34 @@ impl Shell {
|
|||
let mut command = match self {
|
||||
Shell::Cmd => {
|
||||
let mut command = Command::new("cmd");
|
||||
command.args(&["/C", &cmd]);
|
||||
command.args(&["/C", cmd]);
|
||||
command
|
||||
}
|
||||
Shell::Powershell => {
|
||||
let mut command = Command::new("powershell");
|
||||
command.args(&["-Command", &cmd]);
|
||||
command.args(&["-Command", cmd]);
|
||||
command
|
||||
}
|
||||
Shell::WSL => {
|
||||
is_wsl = true;
|
||||
let mut command = Command::new("bash");
|
||||
command.args(&["-c", &cmd]);
|
||||
command.args(&["-c", cmd]);
|
||||
command
|
||||
}
|
||||
Shell::WSL2 => {
|
||||
is_wsl = true;
|
||||
let mut command = Command::new("wsl");
|
||||
command.args(&["bash", "-c", &cmd]);
|
||||
command.args(&["bash", "-c", cmd]);
|
||||
command
|
||||
}
|
||||
Shell::Bash => {
|
||||
let mut command = Command::new("bash");
|
||||
command.args(&["-c", &cmd]);
|
||||
command.args(&["-c", cmd]);
|
||||
command
|
||||
}
|
||||
Shell::Sh => {
|
||||
let mut command = Command::new("sh");
|
||||
command.args(&["-c", &cmd]);
|
||||
command.args(&["-c", cmd]);
|
||||
command
|
||||
}
|
||||
};
|
||||
|
@ -87,8 +87,7 @@ impl Shell {
|
|||
// should be passed to linux.
|
||||
// For more information: https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
|
||||
if is_wsl {
|
||||
let mut tokens: Vec<&str> = Vec::new();
|
||||
tokens.push("CONFIG/p");
|
||||
let mut tokens: Vec<&str> = vec!["CONFIG/p"];
|
||||
|
||||
// Add all the previous variables
|
||||
for (key, _) in vars.iter() {
|
||||
|
@ -166,7 +165,7 @@ impl Extension for ShellExtension {
|
|||
Shell::default()
|
||||
};
|
||||
|
||||
let mut env_variables = super::util::convert_to_env_variables(&scope);
|
||||
let mut env_variables = super::util::convert_to_env_variables(scope);
|
||||
env_variables.insert(
|
||||
"CONFIG".to_string(),
|
||||
self.config_path.to_string_lossy().to_string(),
|
||||
|
|
|
@ -31,7 +31,7 @@ pub trait Renderer {
|
|||
-> RenderResult;
|
||||
}
|
||||
|
||||
pub fn create<'a>(extensions: Vec<&'a dyn Extension>) -> impl Renderer + 'a {
|
||||
pub fn create(extensions: Vec<&dyn Extension>) -> impl Renderer + '_ {
|
||||
renderer::DefaultRenderer::new(extensions)
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ impl<'a> Renderer for DefaultRenderer<'a> {
|
|||
})
|
||||
.collect()
|
||||
} else {
|
||||
template.vars.iter().map(|var| var).collect()
|
||||
template.vars.iter().collect()
|
||||
};
|
||||
|
||||
// The implicit global variables will be evaluated first, followed by the local vars
|
||||
|
@ -154,7 +154,7 @@ impl<'a> Renderer for DefaultRenderer<'a> {
|
|||
match render_variables(&template.body, &scope) {
|
||||
Ok(output) => output,
|
||||
Err(error) => {
|
||||
return RenderResult::Error(error.into());
|
||||
return RenderResult::Error(error);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -196,7 +196,7 @@ impl<'a> Renderer for DefaultRenderer<'a> {
|
|||
pub(crate) fn render_variables(body: &str, scope: &Scope) -> Result<String> {
|
||||
let mut replacing_error = None;
|
||||
let output = VAR_REGEX
|
||||
.replace_all(&body, |caps: &Captures| {
|
||||
.replace_all(body, |caps: &Captures| {
|
||||
let var_name = caps.name("name").unwrap().as_str();
|
||||
let var_subname = caps.name("subname");
|
||||
match scope.get(var_name) {
|
||||
|
@ -230,7 +230,7 @@ pub(crate) fn render_variables(body: &str, scope: &Scope) -> Result<String> {
|
|||
}
|
||||
})
|
||||
.to_string();
|
||||
|
||||
|
||||
if let Some(error) = replacing_error {
|
||||
return Err(error.into());
|
||||
}
|
||||
|
@ -282,24 +282,22 @@ mod tests {
|
|||
scope: &Scope,
|
||||
params: &crate::Params,
|
||||
) -> ExtensionResult {
|
||||
if let Some(value) = params.get("echo") {
|
||||
if let Value::String(string) = value {
|
||||
return ExtensionResult::Success(ExtensionOutput::Single(string.clone()));
|
||||
}
|
||||
if let Some(Value::String(string)) = params.get("echo") {
|
||||
return ExtensionResult::Success(ExtensionOutput::Single(string.clone()));
|
||||
}
|
||||
// If the "read" param is present, echo the value of the corresponding result in the scope
|
||||
if let Some(value) = params.get("read") {
|
||||
if let Value::String(string) = value {
|
||||
if let Some(Value::String(string)) = params.get("read") {
|
||||
if let Some(ExtensionOutput::Single(value)) = scope.get(string.as_str()) {
|
||||
return ExtensionResult::Success(ExtensionOutput::Single(value.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if params.get("abort").is_some() {
|
||||
return ExtensionResult::Aborted;
|
||||
}
|
||||
if params.get("error").is_some() {
|
||||
return ExtensionResult::Error(RendererError::MissingVariable("missing".to_string()).into());
|
||||
return ExtensionResult::Error(
|
||||
RendererError::MissingVariable("missing".to_string()).into(),
|
||||
);
|
||||
}
|
||||
ExtensionResult::Aborted
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use super::VAR_REGEX;
|
|||
|
||||
pub(crate) fn get_body_variable_names(body: &str) -> HashSet<&str> {
|
||||
let mut variables = HashSet::new();
|
||||
for caps in VAR_REGEX.captures_iter(&body) {
|
||||
for caps in VAR_REGEX.captures_iter(body) {
|
||||
let var_name = caps.name("name").unwrap().as_str();
|
||||
variables.insert(var_name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user