diff --git a/example_configs/apt.yaml b/example_configs/apt.yaml index 5d0b64f..6bd8d13 100644 --- a/example_configs/apt.yaml +++ b/example_configs/apt.yaml @@ -16,3 +16,14 @@ executors: params: - apt - autoremove + - name: Zypper + pre_install: + - exe: sudo + params: + - zypper + - refresh + install: + exe: sudo + params: + - zypper + - dup diff --git a/example_configs/cargo.yaml b/example_configs/cargo.yaml new file mode 100644 index 0000000..d0f84c0 --- /dev/null +++ b/example_configs/cargo.yaml @@ -0,0 +1,7 @@ +executors: + - name: Cargo + install: + exe: cargo + params: + - install-update + - -a diff --git a/example_configs/rust.yaml b/example_configs/rust.yaml index 8120c27..7d4867d 100644 --- a/example_configs/rust.yaml +++ b/example_configs/rust.yaml @@ -4,9 +4,3 @@ executors: exe: rustup params: - update - - name: Cargo - install: - exe: cargo - params: - - install-update - - -a diff --git a/src/command.rs b/src/command.rs index 4c47988..8e98985 100644 --- a/src/command.rs +++ b/src/command.rs @@ -98,7 +98,7 @@ pub fn get_packages_folder(opt: &Opt) -> io::Result { impl Updater { fn new() -> Updater { Updater { - packagers: BTreeMap::from([(String::new(), Packager { executors: vec![] })]), + packagers: BTreeMap::default(), } } @@ -218,9 +218,23 @@ impl Updater { // XXX: We may parallelise (iter_par from rayon?) this loop. But the UI will be problematic to handle for (_packager_name, packager) in &self.packagers { + // TODO: default status should be an error, but… in the same time we should not have en empty list + let mut stat = (String::from("No command"), Ok(()).into()); + + assert!(!packager.executors.is_empty()); + for pkg in &packager.executors { - status.push((pkg.name.clone(), self.update(&pkg, opt).into())); + let u = self.update(&pkg, opt); + let is_ok = u.is_ok(); + + stat = (pkg.name.clone(), u.into()); + + if is_ok { + break; + } } + + status.push(stat); } Summary { status } @@ -256,7 +270,7 @@ impl Executor { })?; if !exit_status.success() { - return Err(Error::Execution { + return Result::Err(Error::Execution { source: io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)), step: UpdateSteps::PreInstall, cmd, diff --git a/src/errors.rs b/src/errors.rs index 6d85cfc..f6f9b5a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -8,6 +8,26 @@ use thiserror::Error; pub type Result = result::Result; +/// Result wrapper used to easily `Display` the Status of an execution +pub struct Status { + result: Result<()>, +} + +impl Display for Status { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Status { result: Ok(_) } => write!(f, "Ok"), + Status { result: Err(e) } => write!(f, "Error: {}", e), + } + } +} + +impl From> for Status { + fn from(result: Result<()>) -> Self { + Status { result } + } +} + /// An error that can occur in this crate. /// /// Generally, this error corresponds to problems with underlying process. diff --git a/src/lib.rs b/src/lib.rs index 7df7c60..8976bb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,35 +21,7 @@ pub struct Opt { pub steps: Vec, } -enum Status { - /// All steps asked were successful - Ok, - Err(Error), -} - -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)>, } @@ -74,7 +46,7 @@ pub fn run(opt: &Opt) -> io::Result { return Err(io::Error::new( io::ErrorKind::Other, format!( - "No package found in configuration folder. Add them in: {}", + "No package found in configuration folder. Add them in: '{}'", package_folder.display() ), ));