Add name of updated systems in summary
This commit is contained in:
parent
6769376ae2
commit
1f689b683a
@ -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
|
||||
|
@ -20,7 +20,7 @@ pub struct Updater {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct System {
|
||||
//name: String,
|
||||
pub name: String,
|
||||
fetch: Option<Cmd>,
|
||||
compile: Option<Cmd>,
|
||||
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<()> {
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -28,17 +28,17 @@ pub struct Opt {
|
||||
pub steps: Vec<String>,
|
||||
}
|
||||
|
||||
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<T> From<Result<T>> for State {
|
||||
impl<T> From<Result<T>> for Status {
|
||||
fn from(value: Result<T>) -> 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<State>,
|
||||
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user