Files
sys-compare/src/syscompare.rs

93 lines
2.7 KiB
Rust
Raw Normal View History

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