Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub enum BleurError {
InvalidRepositoryName(String),
#[error("git error: {0}")]
GitError(git2::Error),
#[error("brotha, what on earth makes you want collection more than {0} depths?")]
AintNoWayThisDeepCollection(u8),

// To be used only if you get despaired.
// Until so, don't touch, for the sake of your own sanity!
Expand Down
2 changes: 1 addition & 1 deletion src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Manager {
}

pub fn parse(self) -> Result<Self> {
let template = Configuration::surely_template(self.temporary.path().to_path_buf())?;
let template = Configuration::surely_template(self.temporary.path().to_path_buf(), 1)?;

Ok(Self {
template,
Expand Down
10 changes: 8 additions & 2 deletions src/schemes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::{Error, Result};
use std::fs;
use std::path::PathBuf;

static MAX_COLLECTIONS_DEPTH: u8 = 5;

#[derive(Debug, Default, Clone)]
pub enum Configuration {
// If repo is a single template
Expand Down Expand Up @@ -44,9 +46,13 @@ impl Configuration {
Self::Empty
}

pub fn surely_template(path: PathBuf) -> Result<Self> {
pub fn surely_template(path: PathBuf, depth: u8) -> Result<Self> {
use Configuration::*;

if depth > MAX_COLLECTIONS_DEPTH {
return Err(Error::AintNoWayThisDeepCollection(depth));
}

match Self::parse(path.clone()) {
Template(t) => Ok(Self::Template(t)),
Empty => Err(Error::NoTemplateConfiguration),
Expand All @@ -60,7 +66,7 @@ impl Configuration {

let option = c.select(option).ok_or(Error::NoSuchTemplateInCollection)?;

Self::surely_template(option.path(path))
Self::surely_template(option.path(path), depth + 1)
}
}
}
Expand Down