diff --git a/examples/debian.yml b/examples/debian.yml index 01a1988..fa896b3 100644 --- a/examples/debian.yml +++ b/examples/debian.yml @@ -1,5 +1,6 @@ systems: -- fetch: +- name: Apt + fetch: exe: sudo params: - apt @@ -15,13 +16,15 @@ systems: - --yes current_dir: null env: {} -- install: +- name: Rustup + install: exe: rustup params: - update current_dir: null env: {} -- install: +- name: Cargo + install: exe: cargo params: - install-update diff --git a/src/command.rs b/src/command.rs index ae3a801..84db3db 100644 --- a/src/command.rs +++ b/src/command.rs @@ -20,7 +20,7 @@ pub struct Updater { #[derive(Debug, Serialize, Deserialize)] pub struct System { - //name: String, + pub name: String, fetch: Option, compile: Option, install: Cmd, @@ -74,6 +74,7 @@ impl Updater { fn new() -> Updater { let mut up = Updater { systems: vec![] }; up.systems.push(System { + name: "".into(), fetch: None, compile: None, install: Cmd::new(), @@ -107,11 +108,12 @@ impl Updater { pub fn update_all(&self, opt: &Opt) -> Summary { // self.systems.iter().collect(); - let mut systems: Vec<_> = vec![]; + let mut status: Vec<_> = vec![]; for sys in &self.systems { - systems.push(self.update(&sys, opt).into()); + status.push((sys.name.clone(), self.update(&sys, opt).into())); } - Summary { systems } + + Summary { status } } fn update(&self, sys: &System, opt: &Opt) -> Result<()> { diff --git a/src/lib.rs b/src/lib.rs index 56d6a13..2910cb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,17 +28,17 @@ pub struct Opt { pub steps: Vec, } -enum State { +enum Status { /// All steps asked were successful Ok, Err(MyError), } -impl Display for State { +impl Display for Status { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - State::Ok => write!(f, "Ok"), - State::Err(e) => write!(f, "Error: {}", e), + 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), @@ -46,27 +46,27 @@ impl Display for State { } } -impl From> for State { +impl From> for Status { fn from(value: Result) -> Self { match value { - Ok(_) => State::Ok, - Err(e) => State::Err(e), + Ok(_) => Status::Ok, + Err(e) => Status::Err(e), } } } pub struct Summary { // TODO: Go back to vectors to keep order? - systems: Vec, + status: Vec<(String, Status)>, } impl Display for Summary { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "Summary:")?; - for system in &self.systems { + for (name, status) in &self.status { // TODO: also print version before/after, update time - writeln!(f, "\t{}", system)?; + writeln!(f, "\t{}\t{}", name, status)?; } Ok(()) }