sys-compare/src/syscompare.rs

72 lines
2.1 KiB
Rust
Raw Normal View History

2024-03-18 21:42:04 +00:00
use std::collections::HashMap;
2024-03-18 21:51:52 +00:00
use std::env::args;
2024-03-18 21:42:04 +00:00
use std::sync::{Arc, Mutex};
2024-03-18 20:38:10 +00:00
use Fasching::snapshot::Snapshot;
2024-03-18 22:28:33 +00:00
use crate::comparemode::CompareMode;
2024-03-18 21:51:52 +00:00
use crate::createmode::CreateMode;
2024-03-18 20:38:10 +00:00
2024-03-18 22:28:33 +00:00
pub enum SysCompareMode {
2024-03-18 21:46:19 +00:00
Create,
Compare
2024-03-18 20:38:10 +00:00
}
2024-03-18 21:36:14 +00:00
pub struct SysCompareApp {
2024-03-18 22:28:33 +00:00
mode: SysCompareMode,
2024-03-18 21:42:04 +00:00
args: Vec<String>,
comparatives: Arc<Mutex<HashMap<String, Snapshot>>>
2024-03-18 20:38:10 +00:00
}
2024-03-18 21:36:14 +00:00
impl SysCompareApp {
2024-03-18 22:28:33 +00:00
pub fn new(mode: SysCompareMode, args: Vec<String>) -> SysCompareApp {
2024-03-18 21:42:04 +00:00
SysCompareApp { mode, args, comparatives: Arc::new(Mutex::new(HashMap::new())) }
2024-03-18 21:36:14 +00:00
}
pub fn run(&self) {
println!("running");
2024-03-18 21:51:52 +00:00
match self.mode {
2024-03-18 22:28:33 +00:00
SysCompareMode::Create => {
2024-03-18 22:04:24 +00:00
let in_path = match self.args.get(2) {
None => {panic!("Missing hash dir path as second argument")}
2024-03-18 22:28:33 +00:00
Some(r) => {not_empty(r)}
2024-03-18 21:51:52 +00:00
};
2024-03-18 22:04:24 +00:00
let out_path = match self.args.get(3) {
None => {panic!("Missing output path as third argument")}
2024-03-18 22:28:33 +00:00
Some(r) => {not_empty(r)}
2024-03-18 22:04:24 +00:00
};
let create = CreateMode::new(self.args.clone(), in_path.clone(), out_path.clone());
2024-03-18 21:51:52 +00:00
create.run()
}
2024-03-18 22:28:33 +00:00
SysCompareMode::Compare => {
let left = match self.args.get(2) {
None => {panic!("Missing hash dir path as second argument")}
Some(r) => {not_empty(r)}
};
let right = match self.args.get(3) {
None => {panic!("Missing output path as third argument")}
Some(r) => {not_empty(r)}
};
2024-03-18 22:20:57 +00:00
2024-03-18 22:28:33 +00:00
let compare = CompareMode::new(self.args.clone(), left, right);
2024-03-18 22:20:57 +00:00
}
2024-03-18 21:51:52 +00:00
}
2024-03-18 20:38:10 +00:00
}
}
2024-03-18 22:28:33 +00:00
fn not_empty(r: &String) -> String {
if r.replace("./", "").is_empty() {
panic!("Specify input file name")
} else {
r.to_string()
}
}
2024-03-18 21:36:14 +00:00
impl Default for SysCompareApp {
2024-03-18 20:38:10 +00:00
fn default() -> Self {
2024-03-18 22:28:33 +00:00
SysCompareApp { mode: SysCompareMode::Create, args: vec![], comparatives: Arc::new(Mutex::new(HashMap::new())) }
2024-03-18 20:38:10 +00:00
}
}
2024-03-18 21:36:14 +00:00
pub trait Comparer {
fn run(&self);
}