use std::env;
use perseus::RenderFnResult;
use crate::{errors::ParserError, parser::Config};
pub async fn get_build_paths() -> RenderFnResult<Vec<String>> {
let root_cfg_file_path =
env::var("TRIBBLE_CONF").unwrap_or_else(|_| "../../../examples/basic.yml".to_string());
let root_cfg = Config::new(&root_cfg_file_path)?;
match root_cfg {
Config::Root { languages, .. } => {
match languages.keys().collect::<Vec<&String>>().get(0) {
Some(key) => {
let language_cfg_path = languages.get(&key.to_string()).unwrap(); let language_cfg = Config::new(language_cfg_path)?;
match language_cfg {
Config::Language { workflows, .. } => {
let mut pages = Vec::new();
for workflow_name in workflows.keys() {
for lang in languages.keys() {
pages.push(format!("{}/{}", lang, workflow_name));
}
}
Ok(pages)
}
Config::Root { .. } => Err(ParserError::RootLinksToRoot {
filename: root_cfg_file_path,
linked: language_cfg_path.to_string(),
}
.into()),
}
}
None => Err(ParserError::NoLanguages {
filename: root_cfg_file_path,
}
.into()),
}
}
Config::Language { workflows, .. } => {
Ok(workflows.keys().cloned().collect::<Vec<String>>())
}
}
}