From c3a55debe9e4194f83164d412293f27b797627af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Thu, 20 Jul 2023 22:04:45 +0100 Subject: Initial commit --- src/main.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..08a4f51 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +mod config; +mod install; +mod util; +mod cli; + +use clap::Parser; +use colored::*; +use std::process; +use config::Config; +use util::*; + +fn main() { + let args = cli::Args::parse(); + let install_profile = &args.file; + + let loaded_config: Config = Config::from_file(install_profile).unwrap_or_else(|err| { + eprintln!("Cannot load '{install_profile}': {}", err.to_string()); + process::exit(EXIT_IO_ERROR); + }); + + let num_stages = loaded_config.stages.len(); + for i in 1..=num_stages { + let stage = loaded_config.stages.get(i-1).unwrap(); + let name = stage.name.clone().unwrap(); + let count = format!("[{i}/{num_stages}]").yellow(); + + println!("{} {}", count.bold(), name.bold()); + for step in stage.steps.as_ref().unwrap() { + let step_result = install::run_step(&step, &stage.base_path); + + println!("{}", fmt_step(step, &step_result)); + if step_result.is_err() { + eprintln!("Step failed: {}", step_result.unwrap_err().to_string()); + println!(); + println!("{} {} {} {}{}", "Install stopped at stage".red(), i.to_string().red(), "of".red(), num_stages.to_string().red(), ".".red()); + process::exit(EXIT_INSTALL_FAILED); + } + } + + println!() + } + + println!("{} {} {}", "Install of".bright_green(), install_profile.bright_green(), "completed.".bright_green()) +} + -- cgit v1.2.3-70-g09d2