Skip to content

Commit

Permalink
Merge pull request #55 from perryrh0dan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
perryrh0dan authored Sep 12, 2020
2 parents fceabfd + b94eed8 commit 3640c32
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
}
]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tmpo"
version = "1.5.0"
version = "1.5.1"
authors = ["Thomas Pöhlmann <[email protected]>"]
edition = "2018"

Expand Down
10 changes: 9 additions & 1 deletion src/action/default/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 35 additions & 12 deletions src/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Info {
version: Option<String>
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Template {
pub name: String,
pub path: PathBuf,
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -176,30 +179,37 @@ impl Template {
Ok(())
}

pub fn get_custom_values(&self, repository: &Repository) -> Vec<String> {
pub fn get_custom_values(&self, repository: &Repository) -> Result<Vec<String>, 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<String> = 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 {
Some(x) => values.extend(x.to_owned()),
None => (),
};

values
Ok(values)
}

/// Get list of all super templates
fn get_super_templates(&self, repository: &Repository) -> Vec<Template> {
fn get_super_templates(&self, repository: &Repository) -> Result<Vec<Template>, RunError> {
// get list of all super templates
let super_templates = match &self.meta.extend {
None => Vec::new(),
Expand All @@ -208,11 +218,24 @@ impl Template {

let mut templates = vec!{};
for name in super_templates {
let template = repository.get_template_by_name(&name).unwrap();
templates.extend(template.get_super_templates(repository));
let template = match repository.get_template_by_name(&name) {
Ok(template) => template,
Err(error) => {
log::error!("{}", error);
return Err(RunError::Template(String::from("Not found")));
},
};

let t = match template.get_super_templates(repository) {
Ok(templates) => templates,
Err(error) => return Err(error),
};

templates.extend(t);
templates.push(template.to_owned());
}

templates
Ok(templates)
}

fn is_excluded_renderer(&self, name: &str) -> bool {
Expand Down
18 changes: 11 additions & 7 deletions src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ const BIN_NAME: &str = "tmpo";

pub fn check_version(verbose: bool) -> Option<self_update::update::ReleaseAsset> {
log::info!("Fetch release list");
let releases = self_update::backends::github::ReleaseList::configure()
let releases = match self_update::backends::github::ReleaseList::configure()
.repo_owner("perryrh0dan")
.repo_name("tmpo")
.build()
.unwrap()
.fetch()
.unwrap();
{
Ok(releases) => releases,
Err(error) => {
log::error!("{}", error);
return None
},
};

// check version
// Check version
let version = crate_version!();
if releases[0].version == version {
return None;
}

let mut target = self_update::get_target();

// needs to be investigated
// Needs to be investigated
if target == "x86_64-pc-windows-msvc" {
target = "x86_64-pc-windows-gnu";
}
Expand Down Expand Up @@ -125,9 +131,7 @@ pub fn update(asset: self_update::update::ReleaseAsset) -> Result<(), RunError>
self_update::errors::Error::Io { .. } => {
Err(RunError::Update(String::from("No permission")))
}
_ => {
Err(RunError::Update(String::from("Unknown")))
}
_ => Err(RunError::Update(String::from("Unknown"))),
}
}
};
Expand Down

0 comments on commit 3640c32

Please sign in to comment.