use log::{error, info, warn}; use manifest::CrateManifest; use package::PackageManager; use serde::{Deserialize, Serialize}; pub mod action; pub mod manifest; pub mod package; pub struct Crate { pub manifest: CrateManifest, } impl Crate { pub fn from_toml_str(string: &str) -> Result { Ok(Crate { manifest: toml::from_str::(string)?, }) } pub fn install_packages(&self) -> bool { if let Some(packages) = &self.manifest.packages { info!("Installing packages..."); let pkgs: Vec = packages .iter() .map(|p| p.get_correct_package_name()) .collect(); info!(target: "item", "pkgs: {}", pkgs.join(", ")); if let Some(pm) = PackageManager::get_available() { pm.install(pkgs).is_ok() } else { false } } else { false } } pub fn run_actions(&self) -> Result<(), Box> { if let Some(actions) = &self.manifest.actions { if let Some(commands) = &actions.commands { for command in commands { info!( "Running {}...", &command.description.clone().unwrap_or("action".to_string()) ); command.run()?; } } if let Some(links) = &actions.links { for link in links { info!("Link {} -> {}...", link.src, link.dest); if let Err(e) = link.link() { error!("could not link: {e}"); continue; } } } } Ok(()) } }