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