.
This commit is contained in:
parent
feecfb4948
commit
bc3f85cc85
@ -1,24 +1,27 @@
|
||||
use crate::syscompare::Comparer;
|
||||
use Fasching::snapshot::{Snapshot, SnapshotChangeType, SnapshotCompareResult};
|
||||
use Fasching::{compare_snapshots, import_snapshot};
|
||||
use crate::options::Arguments;
|
||||
|
||||
pub struct CompareMode {
|
||||
left: Snapshot,
|
||||
right: Snapshot,
|
||||
args: Vec<String>,
|
||||
selection: Option<String>,
|
||||
options: Arguments,
|
||||
result_type: SnapshotChangeType,
|
||||
results: SnapshotCompareResult,
|
||||
}
|
||||
|
||||
impl CompareMode {
|
||||
pub fn new(args: Vec<String>, left: String, right: String) -> CompareMode {
|
||||
pub fn new(options: Arguments, left: String, right: String, selection: Option<String>) -> CompareMode {
|
||||
let left = import_snapshot(left);
|
||||
let right = import_snapshot(right);
|
||||
|
||||
CompareMode {
|
||||
left,
|
||||
right,
|
||||
args,
|
||||
selection,
|
||||
options,
|
||||
result_type: SnapshotChangeType::None,
|
||||
results: SnapshotCompareResult {
|
||||
created: vec![],
|
||||
@ -31,9 +34,11 @@ impl CompareMode {
|
||||
|
||||
impl Comparer for CompareMode {
|
||||
fn run(&mut self) {
|
||||
let selector = match self.args.get(4) {
|
||||
let selector = match &self.selection {
|
||||
None => "none",
|
||||
Some(r) => r,
|
||||
Some(r) => {
|
||||
r.as_str()
|
||||
},
|
||||
};
|
||||
|
||||
let results = match compare_snapshots(self.left.clone(), self.right.clone()) {
|
||||
@ -90,11 +95,11 @@ mod tests {
|
||||
let right_dir = format!("/home/{}/Documents/", user);
|
||||
println!("{right}");
|
||||
|
||||
let mut n1 = CreateMode::new(vec![], left.clone(), left_dir);
|
||||
let mut n1 = CreateMode::new(vec![], left.clone());
|
||||
n1.run();
|
||||
let mut n2 = CreateMode::new(vec![], right.clone(), right_dir);
|
||||
let mut n2 = CreateMode::new(vec![], right.clone());
|
||||
n2.run();
|
||||
|
||||
let cm = CompareMode::new(vec![], left.clone(), right.clone());
|
||||
let cm = CompareMode::new(vec![], left.clone(), right.clone(), );
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,46 @@
|
||||
use crate::print_help;
|
||||
use crate::syscompare::Comparer;
|
||||
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use Fasching::hasher::HashType;
|
||||
use Fasching::hasher::HashType::BLAKE3;
|
||||
use Fasching::snapshot::Snapshot;
|
||||
use Fasching::{create_snapshot, export_snapshot};
|
||||
use crate::options::Arguments;
|
||||
use crate::syscompare::Comparer;
|
||||
|
||||
pub struct CreateMode {
|
||||
snapshot_path: String,
|
||||
root_path: String,
|
||||
#[allow(unused)]
|
||||
args: Vec<String>,
|
||||
snapshot: Snapshot,
|
||||
}
|
||||
|
||||
impl CreateMode {
|
||||
pub fn new(args: Vec<String>, snapshot_path: String, root_path: String) -> CreateMode {
|
||||
pub fn new(snapshot_path: String, root_path: String) -> CreateMode {
|
||||
if snapshot_path.replace("./", "").is_empty() {
|
||||
println!("Specify output file name");
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
let bind = root_path.clone();
|
||||
let rp = bind.as_str();
|
||||
|
||||
CreateMode {
|
||||
args,
|
||||
snapshot_path,
|
||||
root_path,
|
||||
snapshot: create_snapshot(rp, HashType::MD5, vec![]),
|
||||
snapshot: Snapshot {
|
||||
file_hashes: Arc::new(Mutex::new(Default::default())),
|
||||
black_list: vec![],
|
||||
root_path: "".to_string(),
|
||||
hash_type: BLAKE3,
|
||||
uuid: "".to_string(),
|
||||
date_created: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Comparer for CreateMode {
|
||||
fn run(&mut self) {
|
||||
impl CreateMode {
|
||||
pub fn run(&mut self) {
|
||||
let snapshot = create_snapshot(self.root_path.as_str(), BLAKE3, vec![]);
|
||||
self.snapshot = snapshot.clone();
|
||||
if let Ok(e) = snapshot.file_hashes.lock() {
|
||||
|
38
src/main.rs
38
src/main.rs
@ -3,45 +3,35 @@ pub mod createmode;
|
||||
pub mod syscompare;
|
||||
mod options;
|
||||
|
||||
use crate::syscompare::SysCompareApp;
|
||||
use crate::syscompare::SysCompareMode::{Compare, Create};
|
||||
|
||||
use std::env::args;
|
||||
use std::process::exit;
|
||||
use clap::{FromArgMatches, Parser};
|
||||
use crate::comparemode::CompareMode;
|
||||
use crate::createmode::CreateMode;
|
||||
use crate::options::{Arguments, Commands};
|
||||
use crate::syscompare::Comparer;
|
||||
|
||||
fn main() {
|
||||
let options = Arguments::parse();
|
||||
|
||||
let movable = options.clone();
|
||||
let args: Vec<String> = args().collect();
|
||||
// println!("{:#?}", args); // testing
|
||||
|
||||
let app = match options.command {
|
||||
None => {
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
None => {}
|
||||
Some(Commands::Create { root_dir, output_path }) => {
|
||||
// app mode
|
||||
|
||||
// let app_mode = match m {
|
||||
// "create" => Create,
|
||||
// "compare" => Compare,
|
||||
// _ => {
|
||||
// println!("Invalid MODE argument");
|
||||
// print_help();
|
||||
// exit(0);
|
||||
// }
|
||||
// };
|
||||
|
||||
SysCompareApp::new(Create, args)
|
||||
let mut create =
|
||||
CreateMode::new(output_path, root_dir);
|
||||
println!("Creating snapshot..");
|
||||
create.run()
|
||||
},
|
||||
Some(Commands::Compare { left, right }) => {
|
||||
SysCompareApp::new(Compare, args)
|
||||
Some(Commands::Compare { left, right, selection }) => {
|
||||
println!("Running snapshot comparison..");
|
||||
let mut compare = CompareMode::new(movable.clone(), left, right, selection);
|
||||
compare.run()
|
||||
}
|
||||
};
|
||||
|
||||
app.run()
|
||||
}
|
||||
|
||||
pub fn print_help() {
|
||||
|
@ -1,16 +1,18 @@
|
||||
use clap::{Command, Parser, Subcommand};
|
||||
use crate::syscompare::SysCompareMode;
|
||||
|
||||
#[derive(Parser)]
|
||||
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
pub struct Arguments {
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Commands>,
|
||||
#[arg(short, long)]
|
||||
pub input_path: Option<String>,
|
||||
#[arg(short, long)]
|
||||
pub output_path: Option<String>,
|
||||
pub show: Option<String>,
|
||||
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
#[derive(Subcommand, Clone, Debug)]
|
||||
pub enum Commands {
|
||||
Create {
|
||||
#[arg(short, long)]
|
||||
@ -23,5 +25,7 @@ pub enum Commands {
|
||||
left: String,
|
||||
#[arg(short, long)]
|
||||
right: String,
|
||||
#[arg(short, long)]
|
||||
selection: Option<String>,
|
||||
},
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use Fasching::snapshot::Snapshot;
|
||||
use crate::options::Arguments;
|
||||
|
||||
pub enum SysCompareMode {
|
||||
Create,
|
||||
@ -13,16 +14,16 @@ pub enum SysCompareMode {
|
||||
|
||||
pub struct SysCompareApp {
|
||||
mode: SysCompareMode,
|
||||
args: Vec<String>,
|
||||
options: Arguments,
|
||||
#[allow(unused)]
|
||||
comparatives: Arc<Mutex<HashMap<String, Snapshot>>>,
|
||||
}
|
||||
|
||||
impl SysCompareApp {
|
||||
pub fn new(mode: SysCompareMode, args: Vec<String>) -> SysCompareApp {
|
||||
pub fn new(mode: SysCompareMode, options: Arguments) -> SysCompareApp {
|
||||
SysCompareApp {
|
||||
mode,
|
||||
args,
|
||||
options,
|
||||
comparatives: Arc::new(Mutex::new(HashMap::new())),
|
||||
}
|
||||
}
|
||||
@ -30,67 +31,55 @@ impl SysCompareApp {
|
||||
println!("running");
|
||||
match self.mode {
|
||||
SysCompareMode::Create => {
|
||||
let snapshot_path = match self.args.get(2) {
|
||||
None => {
|
||||
println!("Missing hash dir path as second argument");
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
Some(r) => not_empty(r),
|
||||
};
|
||||
let root_dir = match self.args.get(3) {
|
||||
None => {
|
||||
println!("Missing hash dir path as second argument");
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
Some(r) => not_empty(r),
|
||||
};
|
||||
let mut create =
|
||||
CreateMode::new(self.args.clone(), snapshot_path.clone(), root_dir.clone());
|
||||
create.run()
|
||||
// let mut create =
|
||||
// CreateMode::new(self.options.clone(), snapshot_path.clone(), root_dir.clone());
|
||||
// create.run()
|
||||
}
|
||||
SysCompareMode::Compare => {
|
||||
let left = match self.args.get(2) {
|
||||
None => {
|
||||
println!("Missing hash dir path as second argument");
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
Some(r) => not_empty(r),
|
||||
};
|
||||
let right = match self.args.get(3) {
|
||||
None => {
|
||||
println!("Missing output path as third argument");
|
||||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
Some(r) => not_empty(r),
|
||||
};
|
||||
// let left = match self.args.get(2) {
|
||||
// None => {
|
||||
// println!("Missing hash dir path as second argument");
|
||||
// print_help();
|
||||
// exit(0);
|
||||
// }
|
||||
// Some(r) => not_empty(r),
|
||||
// };
|
||||
// let right = match self.args.get(3) {
|
||||
// None => {
|
||||
// println!("Missing output path as third argument");
|
||||
// print_help();
|
||||
// exit(0);
|
||||
// }
|
||||
// Some(r) => not_empty(r),
|
||||
// };
|
||||
|
||||
let mut compare = CompareMode::new(self.args.clone(), left, right);
|
||||
compare.run()
|
||||
// let mut compare = CompareMode::new(self.args.clone(), left, right);
|
||||
// compare.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn not_empty(r: &String) -> String {
|
||||
if r.replace("./", "").is_empty() {
|
||||
println!("Specify input file name");
|
||||
print_help();
|
||||
exit(0);
|
||||
} else {
|
||||
r.to_string()
|
||||
}
|
||||
}
|
||||
// fn not_empty(r: &String) -> String {
|
||||
// if r.replace("./", "").is_empty() {
|
||||
// println!("Specify input file name");
|
||||
// print_help();
|
||||
// exit(0);
|
||||
// } else {
|
||||
// r.to_string()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Default for SysCompareApp {
|
||||
fn default() -> Self {
|
||||
SysCompareApp {
|
||||
mode: SysCompareMode::Create,
|
||||
args: vec![],
|
||||
comparatives: Arc::new(Mutex::new(HashMap::new())),
|
||||
options: Arguments {
|
||||
command: None,
|
||||
input_path: None,
|
||||
output_path: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user