From c61a7b605a1ca995ad49bca17d6dc09e95d9e353 Mon Sep 17 00:00:00 2001 From: landon Date: Wed, 16 Sep 2026 18:49:46 -0500 Subject: [PATCH] fix: Add effective_project_template() to fallback to bundled template - Add effective_project_template() method that checks if saved template path exists - If not, falls back to default_project_template() (bundled template) - This handles users who have old config.json pointing to deleted Cookiecutters path - Update project.rs to use effective_project_template() when creating new projects Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- src/app/project.rs | 6 +++--- src/config.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app/project.rs b/src/app/project.rs index 8cb47f0..7ebfecd 100644 --- a/src/app/project.rs +++ b/src/app/project.rs @@ -61,7 +61,7 @@ impl App { self.np_status = format!("{} already exists.", parent.join(&name).display()); return; } - let template = self.config.project_template.clone(); + let template = self.config.effective_project_template(); // Check that the template directory exists if !template.is_dir() { @@ -600,8 +600,8 @@ impl App { if browse_template { let mut dialog = rfd::FileDialog::new().set_title("Choose a cookiecutter template"); - if self.config.project_template.is_dir() { - dialog = dialog.set_directory(&self.config.project_template); + if self.config.effective_project_template().is_dir() { + dialog = dialog.set_directory(&self.config.effective_project_template()); } if let Some(path) = dialog.pick_folder() { self.config.project_template = path; diff --git a/src/config.rs b/src/config.rs index c6248ed..c3dd2ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -427,6 +427,17 @@ impl Config { } } + /// The project template path to use, falling back to the bundled template + /// if the saved path doesn't exist. + pub fn effective_project_template(&self) -> PathBuf { + // If the saved template path exists and has cookiecutter.json, use it + if self.project_template.join("cookiecutter.json").is_file() { + return self.project_template.clone(); + } + // Otherwise fall back to the bundled template + default_project_template() + } + pub fn load() -> Config { let path = config_path(); match std::fs::read_to_string(&path) {