Skip to content

Commit 4011cf3

Browse files
author
apatton
committed
fix issue with replacing entire argument
1 parent 7040a14 commit 4011cf3

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/book/runtime.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ impl<'a> FunctionRef<'a> {
198198
.map_err(|e| anyhow!(e))?
199199
.as_str();
200200
let var_default = caps.get(3).map(|m| m.as_str());
201+
let full_match = caps.get(0).unwrap().as_str();
201202

202203
// read variable from the environment if the name starts with env. or ENV.
203-
if var_name.starts_with("env.") || var_name.starts_with("ENV.") {
204+
let replacement_value = if var_name.starts_with("env.") || var_name.starts_with("ENV.") {
204205
let env_var_name = var_name.replace("env.", "").replace("ENV.", "");
205206
let env_var = std::env::var(&env_var_name);
206207
let env_var_value = if let Ok(value) = env_var {
@@ -235,7 +236,10 @@ impl<'a> FunctionRef<'a> {
235236
default_value.to_string()
236237
} else {
237238
return Err(anyhow::anyhow!("argument {} not provided", var_name));
238-
}
239+
};
240+
241+
// Replace only the pattern within the argument
242+
arg.replace(full_match, &replacement_value)
239243
} else {
240244
arg
241245
});

0 commit comments

Comments
 (0)