MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / execute

Method execute

src/commands/template/edit.rs:15–45  ·  view source on GitHub ↗
(&self, ctx: &AppContext)

Source from the content-addressed store, hash-verified

13#[async_trait]
14impl Command for TemplateEditCommand {
15 async fn execute(&self, ctx: &AppContext) -> Result<(), Box<dyn Error>> {
16 let project_root = find_repository_root(Path::new(".")).ok();
17 let tsk_env = ctx.tsk_env();
18
19 let path = match find_template_path(&self.name, project_root.as_deref(), &tsk_env) {
20 Some(path) => path,
21 None => {
22 // Template is embedded-only; copy to user templates dir
23 let content = find_template(&self.name, project_root.as_deref(), &tsk_env)?;
24 let user_templates_dir = tsk_env.config_dir().join("templates");
25 std::fs::create_dir_all(&user_templates_dir)?;
26 let dest = user_templates_dir.join(format!("{}.md", self.name));
27 std::fs::write(&dest, &content)?;
28 eprintln!(
29 "Copied built-in template '{}' to {} for editing",
30 self.name,
31 dest.display()
32 );
33 dest
34 }
35 };
36
37 let editor = tsk_env.editor();
38 let status = std::process::Command::new(editor).arg(&path).status()?;
39
40 if !status.success() {
41 return Err(format!("Editor '{}' exited with non-zero status", editor).into());
42 }
43
44 Ok(())
45 }
46}
47
48#[cfg(test)]

Calls 8

find_repository_rootFunction · 0.85
find_template_pathFunction · 0.85
find_templateFunction · 0.85
tsk_envMethod · 0.80
config_dirMethod · 0.80
editorMethod · 0.80
statusMethod · 0.80
successMethod · 0.80