MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / render_template

Method render_template

crates/opencode-command/src/lib.rs:220–242  ·  view source on GitHub ↗
(&self, template: &str, ctx: CommandContext)

Source from the content-addressed store, hash-verified

218 }
219
220 fn render_template(&self, template: &str, ctx: CommandContext) -> String {
221 let mut result = template.to_string();
222
223 for (i, arg) in ctx.arguments.iter().enumerate() {
224 let placeholder = format!("${}", i + 1);
225 result = result.replace(&placeholder, arg);
226 }
227
228 let all_args = ctx.arguments.join(" ");
229 result = result.replace("$ARGUMENTS", &all_args);
230
231 for (key, value) in &ctx.variables {
232 let placeholder = format!("${{{}}}", key);
233 result = result.replace(&placeholder, value);
234 }
235
236 for (key, value) in std::env::vars() {
237 let placeholder = format!("$ENV_{}", key);
238 result = result.replace(&placeholder, &value);
239 }
240
241 result
242 }
243}
244
245fn command_payload_object(

Callers 3

executeMethod · 0.80
execute_with_hooksMethod · 0.80
test_render_templateFunction · 0.80

Calls 1

replaceMethod · 0.80

Tested by 1

test_render_templateFunction · 0.64