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 <vibe@mistral.ai>
This commit is contained in:
+3
-3
@@ -61,7 +61,7 @@ impl App {
|
|||||||
self.np_status = format!("{} already exists.", parent.join(&name).display());
|
self.np_status = format!("{} already exists.", parent.join(&name).display());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let template = self.config.project_template.clone();
|
let template = self.config.effective_project_template();
|
||||||
|
|
||||||
// Check that the template directory exists
|
// Check that the template directory exists
|
||||||
if !template.is_dir() {
|
if !template.is_dir() {
|
||||||
@@ -600,8 +600,8 @@ impl App {
|
|||||||
|
|
||||||
if browse_template {
|
if browse_template {
|
||||||
let mut dialog = rfd::FileDialog::new().set_title("Choose a cookiecutter template");
|
let mut dialog = rfd::FileDialog::new().set_title("Choose a cookiecutter template");
|
||||||
if self.config.project_template.is_dir() {
|
if self.config.effective_project_template().is_dir() {
|
||||||
dialog = dialog.set_directory(&self.config.project_template);
|
dialog = dialog.set_directory(&self.config.effective_project_template());
|
||||||
}
|
}
|
||||||
if let Some(path) = dialog.pick_folder() {
|
if let Some(path) = dialog.pick_folder() {
|
||||||
self.config.project_template = path;
|
self.config.project_template = path;
|
||||||
|
|||||||
@@ -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 {
|
pub fn load() -> Config {
|
||||||
let path = config_path();
|
let path = config_path();
|
||||||
match std::fs::read_to_string(&path) {
|
match std::fs::read_to_string(&path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user