mod command; mod errors; use command::*; use errors::*; use clap::Parser; use std::fmt::Display; use std::path::PathBuf; #[derive(Parser)] pub struct Opt { // TODO: transform this to "base" folder? // XXX: use the directory/directory-next crate to get the "~/.config/sup" folder? // ++ A config subFolder and execute in alphabetical order? // + One config file? -> confy crate? // - A master config file that list the sub/real files? no if it mean parsing 2 differents formats // // Default to something like -> "~/.config/system-updater/list.yml".into(), // //#[arg(default_value_t = PathBuf::from("examples/debian.yml"))] pub config_file: PathBuf, #[arg(short, long)] pub quiet: bool, // TODO: use clap_verbosity_flag instead #[arg(short, long)] pub steps: Vec, } enum Status { /// All steps asked were successful Ok, Err(MyError), } impl Display for Status { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Status::Ok => write!(f, "Ok"), Status::Err(e) => write!(f, "Error: {}", e), // State::Fetch(e) => write!(f, "Fetch error: {}", e), // State::Compile(e) => write!(f, "Compile error: {}", e), // State::Install(e) => write!(f, "Install error: {}", e), } } } impl From> for Status { fn from(value: Result) -> Self { match value { Ok(_) => Status::Ok, Err(e) => Status::Err(e), } } } pub struct Summary { // TODO: Go back to vectors to keep order? status: Vec<(String, Status)>, } impl Display for Summary { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "Summary:")?; for (name, status) in &self.status { // TODO: also print version before/after, update time writeln!(f, "\t{}\t{}", name, status)?; } Ok(()) } } pub fn run(opt: &Opt) -> Summary { let updater = Updater::from_config(opt).unwrap(); updater.update_all(opt) }