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