feat!: Remove legacy code"
This commit is contained in:
parent
006966bb35
commit
785fc2f762
4 changed files with 3 additions and 157 deletions
63
src/lib.rs
63
src/lib.rs
|
|
@ -8,16 +8,9 @@
|
|||
//! to use both features at the same time. For now the 'legacy' feature
|
||||
//! is the default feature until modules works 1-1 with ublue starting point.
|
||||
|
||||
#[cfg(all(feature = "legacy", feature = "modules"))]
|
||||
compile_error!("Both 'legacy' and 'modules' features cannot be used at the same time.");
|
||||
|
||||
#[cfg(feature = "init")]
|
||||
pub mod init;
|
||||
|
||||
#[cfg(feature = "legacy")]
|
||||
pub mod recipe;
|
||||
|
||||
#[cfg(feature = "modules")]
|
||||
pub mod module_recipe;
|
||||
|
||||
use std::{
|
||||
|
|
@ -27,27 +20,15 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use cfg_if;
|
||||
use module_recipe::Recipe;
|
||||
use tera::{Context, Tera};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "legacy")] {
|
||||
use recipe::Recipe;
|
||||
use std::fs::read_dir;
|
||||
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.legacy");
|
||||
} else if #[cfg(feature = "modules")] {
|
||||
use module_recipe::Recipe;
|
||||
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.modules");
|
||||
}
|
||||
}
|
||||
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera");
|
||||
|
||||
pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Tera, Context)> {
|
||||
let recipe_de =
|
||||
serde_yaml::from_str::<Recipe>(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;
|
||||
|
||||
#[cfg(feature = "legacy")]
|
||||
let recipe_de = recipe_de.process_repos();
|
||||
|
||||
let mut context = Context::from_serialize(recipe_de)?;
|
||||
context.insert("recipe", &recipe);
|
||||
|
||||
|
|
@ -65,12 +46,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
|||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||
match args.get("containerfile") {
|
||||
Some(v) => match v.as_str() {
|
||||
#[cfg(feature = "legacy")]
|
||||
Some(containerfile) => Ok(read_to_string(format!(
|
||||
"containerfiles/{containerfile}/Containerfile"
|
||||
))?
|
||||
.into()),
|
||||
#[cfg(feature = "modules")]
|
||||
Some(containerfile) => Ok(read_to_string(format!(
|
||||
"config/containerfiles/{containerfile}/Containerfile"
|
||||
))?
|
||||
|
|
@ -82,7 +57,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "modules")]
|
||||
tera.register_function(
|
||||
"print_module_context",
|
||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||
|
|
@ -97,7 +71,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "modules")]
|
||||
tera.register_function(
|
||||
"get_module_from_file",
|
||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||
|
|
@ -119,37 +92,5 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "legacy")]
|
||||
tera.register_function(
|
||||
"print_autorun_scripts",
|
||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||
match args.get("mode") {
|
||||
Some(v) => match from_value::<String>(v.clone()) {
|
||||
Ok(mode) if mode == "pre" || mode == "post" => {
|
||||
Ok(read_dir(format!("scripts/{mode}"))?
|
||||
.fold(String::from(""), |mut acc: String, script| match script {
|
||||
Ok(entry) => {
|
||||
let file_name = entry.file_name();
|
||||
if let Some(file_name) = file_name.to_str() {
|
||||
if file_name.ends_with(".sh") {
|
||||
acc += format!(
|
||||
"RUN /tmp/scripts/{mode}/{file_name} {mode}\n"
|
||||
)
|
||||
.as_str();
|
||||
}
|
||||
}
|
||||
acc
|
||||
}
|
||||
Err(_) => acc,
|
||||
})
|
||||
.into())
|
||||
}
|
||||
_ => Err("Mode must be pre/post".into()),
|
||||
},
|
||||
None => Err("Need arg 'mode' set with 'pre' or 'post'".into()),
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Ok((tera, context))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue