use std::str::FromStr; use serde::{Deserialize, Serialize}; use toml; use manifest::{self, Manifest}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PKGR { pub bootstrap: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Bootstrap { pub check_installed_commands: Vec, pub commands: Vec, } #[derive(Serialize, Deserialize)] pub struct BadManifest { pkgr: Option, } pub fn mani_from_str(s: &str) -> Manifest> { let mani = Manifest::from_str(s).unwrap(); let bmani = toml::from_str::(s).unwrap(); Manifest::> { package: mani.package, dependencies: mani.dependencies, fs: mani.fs, bin: mani.bin, build: mani.build, pkgr: bmani.pkgr, } } pub fn run_bootstrap(mani: Manifest>) -> bool { if let Some(pkgr) = mani.pkgr { if let Some(bootstrap) = pkgr.bootstrap { fn run_command>(s: S) -> i32 { std::process::Command::new("sh") .arg("-c") .arg(s.into()) .spawn() .expect("Could not spawn process.") .wait() .expect("Could not wait for process.") .code() .expect("Could not fetch exit code.") } for command in &bootstrap.check_installed_commands { if run_command(command) != 0 { println!("!! Command failed: {}", command); println!("!! Already installed."); return false; } } for command in &bootstrap.commands { if run_command(command) != 0 { println!("!! Command failed: {}", command); println!("!! Bootstrap failed!!!"); return false; } } } } return true; }