.
This commit is contained in:
parent
a26077c976
commit
bbeafdad7e
@ -1,20 +1,27 @@
|
||||
use crate::options::Arguments;
|
||||
use anyhow::Error;
|
||||
use filesystem_hashing::snapshot::{Snapshot, SnapshotChangeType, SnapshotCompareResult};
|
||||
use filesystem_hashing::{compare_snapshots, import_snapshot};
|
||||
use crate::options::Arguments;
|
||||
|
||||
pub struct CompareMode {
|
||||
left: Snapshot,
|
||||
right: Snapshot,
|
||||
selection: Option<String>,
|
||||
count_only: Option<bool>,
|
||||
#[allow(unused)]
|
||||
options: Arguments,
|
||||
result_type: SnapshotChangeType,
|
||||
results: SnapshotCompareResult,
|
||||
}
|
||||
|
||||
impl CompareMode {
|
||||
pub fn new(options: Arguments, left: String, right: String, selection: Option<String>, count_only: Option<bool>) -> CompareMode {
|
||||
pub fn new(
|
||||
options: Arguments,
|
||||
left: String,
|
||||
right: String,
|
||||
selection: Option<String>,
|
||||
count_only: Option<bool>,
|
||||
) -> CompareMode {
|
||||
let left = import_snapshot(left).unwrap_or_default();
|
||||
let right = import_snapshot(right).unwrap_or_default();
|
||||
|
||||
@ -38,9 +45,7 @@ impl CompareMode {
|
||||
pub(crate) fn run(&mut self) -> Result<(), Error> {
|
||||
let selector = match &self.selection {
|
||||
None => "none",
|
||||
Some(r) => {
|
||||
r.as_str()
|
||||
},
|
||||
Some(r) => r.as_str(),
|
||||
};
|
||||
|
||||
let results = match compare_snapshots(self.left.clone(), self.right.clone()) {
|
||||
@ -51,7 +56,8 @@ impl CompareMode {
|
||||
self.result_type = results.0;
|
||||
|
||||
macro_rules! print_if_not_empty {
|
||||
($ret:expr, $co:expr) => {if let Some(count_only) = $co {
|
||||
($ret:expr, $co:expr) => {
|
||||
if let Some(count_only) = $co {
|
||||
if count_only {
|
||||
println!("{}", $ret.len());
|
||||
} else {
|
||||
@ -65,8 +71,7 @@ impl CompareMode {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Ok(match selector {
|
||||
match selector {
|
||||
"created" => {
|
||||
print_if_not_empty!(self.results.created, self.count_only);
|
||||
}
|
||||
@ -86,13 +91,11 @@ impl CompareMode {
|
||||
println!("Deleted: {:?}", self.results.deleted.len());
|
||||
println!("Changed: {:?}", self.results.changed.len());
|
||||
}
|
||||
})
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::comparemode::CompareMode;
|
||||
@ -117,6 +120,6 @@ mod tests {
|
||||
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,9 +1,9 @@
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use anyhow::Error;
|
||||
use filesystem_hashing::hasher::HashType::BLAKE3;
|
||||
use filesystem_hashing::snapshot::Snapshot;
|
||||
use filesystem_hashing::{create_snapshot, export_snapshot};
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub struct CreateMode {
|
||||
snapshot_path: String,
|
||||
@ -18,7 +18,7 @@ impl CreateMode {
|
||||
exit(0);
|
||||
}
|
||||
let bind = root_path.clone();
|
||||
let rp = bind.as_str();
|
||||
let _rp = bind.as_str();
|
||||
|
||||
CreateMode {
|
||||
snapshot_path,
|
||||
|
19
src/main.rs
19
src/main.rs
@ -2,23 +2,30 @@ pub mod comparemode;
|
||||
pub mod createmode;
|
||||
mod options;
|
||||
|
||||
use clap::{FromArgMatches, Parser};
|
||||
use crate::comparemode::CompareMode;
|
||||
use crate::createmode::CreateMode;
|
||||
use crate::options::{Arguments, Commands};
|
||||
use clap::Parser;
|
||||
|
||||
fn main() {
|
||||
let options = Arguments::parse();
|
||||
let movable = options.clone();
|
||||
|
||||
let _app = match options.command {
|
||||
Commands::Create { root_dir, output_path } => {
|
||||
let mut create =
|
||||
CreateMode::new(output_path, root_dir);
|
||||
Commands::Create {
|
||||
root_dir,
|
||||
output_path,
|
||||
} => {
|
||||
let mut create = CreateMode::new(output_path, root_dir);
|
||||
println!("Creating snapshot..");
|
||||
create.run()
|
||||
},
|
||||
Commands::Compare { left, right, selection, count_only } => {
|
||||
}
|
||||
Commands::Compare {
|
||||
left,
|
||||
right,
|
||||
selection,
|
||||
count_only,
|
||||
} => {
|
||||
if let Some(count_only) = count_only {
|
||||
if !count_only {
|
||||
println!("Running snapshot comparison..");
|
||||
|
@ -1,6 +1,5 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
pub struct Arguments {
|
||||
#[command(subcommand)]
|
||||
|
Loading…
Reference in New Issue
Block a user