From 3f1e34fd1d8de2e6caade5214a5138797dcff29b Mon Sep 17 00:00:00 2001 From: perryrh0dan Date: Sat, 12 Sep 2020 20:42:34 +0200 Subject: [PATCH 1/2] fix(repository): super_templates are working again --- .vscode/launch.json | 2 +- src/action/default/init.rs | 10 +++++++- src/template/mod.rs | 47 ++++++++++++++++++++++++++++---------- src/update/mod.rs | 18 +++++++++------ 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 94876d3..608886c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ // "args": ["update"], // "args": ["init", "-r", "https://github.com/perryrh0dan/templates", "-t", "typescript"], // "args": ["repository", "add"], - "args": ["init", "ttttt", "-r", "test"], + "args": ["init", "-r", "default", "-t", "golang"], "cwd": "${workspaceRoot}", } ] diff --git a/src/action/default/init.rs b/src/action/default/init.rs index 176f356..47d920d 100644 --- a/src/action/default/init.rs +++ b/src/action/default/init.rs @@ -171,7 +171,15 @@ pub fn init(config: &Config, args: &ArgMatches) { // Get template specific values let mut values = HashMap::new(); - let keys = template.get_custom_values(&repository); + let keys = match template.get_custom_values(&repository) { + Ok(keys) => keys, + Err(error) => { + log::error!("{}", error); + println!("{}", error); + exit(1); + } + }; + for key in keys { let value = match input::text(&format!("Please enter {}", &key), true) { Ok(value) => value, diff --git a/src/template/mod.rs b/src/template/mod.rs index 38c1467..02b3ba1 100644 --- a/src/template/mod.rs +++ b/src/template/mod.rs @@ -22,7 +22,7 @@ pub struct Info { version: Option } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Template { pub name: String, pub path: PathBuf, @@ -67,7 +67,10 @@ impl Template { pub fn copy(&self, repository: &Repository, target: &Path, opts: &context::Context) -> Result<(), RunError> { // Get list of all super templates - let super_templates = self.get_super_templates(repository); + let super_templates = match self.get_super_templates(repository) { + Ok(templates) => templates, + Err(error) => return Err(error), + }; for template in super_templates { template.copy(repository, target, opts)?; @@ -176,18 +179,25 @@ impl Template { Ok(()) } - pub fn get_custom_values(&self, repository: &Repository) -> Vec { + pub fn get_custom_values(&self, repository: &Repository) -> Result, RunError> { // Get list of all super templates - let super_templates = self.get_super_templates(repository); + let super_templates = match self.get_super_templates(repository) { + Ok(templates) => templates, + Err(error) => return Err(error), + }; - let mut values = vec!{}; + let mut values: Vec = vec!{}; for template in super_templates { - values.extend(template.get_custom_values(repository)); + let v = match template.get_custom_values(repository) { + Ok(values) => values, + Err(error) => return Err(error), + }; + values.extend(v); } let renderer = match self.meta.renderer.to_owned() { Some(data) => data, - None => return values, + None => return Ok(values), }; match renderer.values { @@ -195,11 +205,11 @@ impl Template { None => (), }; - values + Ok(values) } /// Get list of all super templates - fn get_super_templates(&self, repository: &Repository) -> Vec