Add name of updated systems in summary

This commit is contained in:
Zykino 2023-01-29 00:46:58 +01:00
parent 6769376ae2
commit 1f689b683a
3 changed files with 22 additions and 17 deletions

View File

@ -1,5 +1,6 @@
systems: systems:
- fetch: - name: Apt
fetch:
exe: sudo exe: sudo
params: params:
- apt - apt
@ -15,13 +16,15 @@ systems:
- --yes - --yes
current_dir: null current_dir: null
env: {} env: {}
- install: - name: Rustup
install:
exe: rustup exe: rustup
params: params:
- update - update
current_dir: null current_dir: null
env: {} env: {}
- install: - name: Cargo
install:
exe: cargo exe: cargo
params: params:
- install-update - install-update

View File

@ -20,7 +20,7 @@ pub struct Updater {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct System { pub struct System {
//name: String, pub name: String,
fetch: Option<Cmd>, fetch: Option<Cmd>,
compile: Option<Cmd>, compile: Option<Cmd>,
install: Cmd, install: Cmd,
@ -74,6 +74,7 @@ impl Updater {
fn new() -> Updater { fn new() -> Updater {
let mut up = Updater { systems: vec![] }; let mut up = Updater { systems: vec![] };
up.systems.push(System { up.systems.push(System {
name: "".into(),
fetch: None, fetch: None,
compile: None, compile: None,
install: Cmd::new(), install: Cmd::new(),
@ -107,11 +108,12 @@ impl Updater {
pub fn update_all(&self, opt: &Opt) -> Summary { pub fn update_all(&self, opt: &Opt) -> Summary {
// self.systems.iter().collect(); // self.systems.iter().collect();
let mut systems: Vec<_> = vec![]; let mut status: Vec<_> = vec![];
for sys in &self.systems { 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<()> { fn update(&self, sys: &System, opt: &Opt) -> Result<()> {

View File

@ -28,17 +28,17 @@ pub struct Opt {
pub steps: Vec<String>, pub steps: Vec<String>,
} }
enum State { enum Status {
/// All steps asked were successful /// All steps asked were successful
Ok, Ok,
Err(MyError), Err(MyError),
} }
impl Display for State { impl Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
State::Ok => write!(f, "Ok"), Status::Ok => write!(f, "Ok"),
State::Err(e) => write!(f, "Error: {}", e), Status::Err(e) => write!(f, "Error: {}", e),
// State::Fetch(e) => write!(f, "Fetch error: {}", e), // State::Fetch(e) => write!(f, "Fetch error: {}", e),
// State::Compile(e) => write!(f, "Compile error: {}", e), // State::Compile(e) => write!(f, "Compile error: {}", e),
// State::Install(e) => write!(f, "Install error: {}", e), // State::Install(e) => write!(f, "Install error: {}", e),
@ -46,27 +46,27 @@ impl Display for State {
} }
} }
impl<T> From<Result<T>> for State { impl<T> From<Result<T>> for Status {
fn from(value: Result<T>) -> Self { fn from(value: Result<T>) -> Self {
match value { match value {
Ok(_) => State::Ok, Ok(_) => Status::Ok,
Err(e) => State::Err(e), Err(e) => Status::Err(e),
} }
} }
} }
pub struct Summary { pub struct Summary {
// TODO: Go back to vectors to keep order? // TODO: Go back to vectors to keep order?
systems: Vec<State>, status: Vec<(String, Status)>,
} }
impl Display for Summary { impl Display for Summary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Summary:")?; writeln!(f, "Summary:")?;
for system in &self.systems { for (name, status) in &self.status {
// TODO: also print version before/after, update time // TODO: also print version before/after, update time
writeln!(f, "\t{}", system)?; writeln!(f, "\t{}\t{}", name, status)?;
} }
Ok(()) Ok(())
} }