diff --git a/src/comparemode.rs b/src/comparemode.rs index 521cacb..32a4ed0 100644 --- a/src/comparemode.rs +++ b/src/comparemode.rs @@ -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, count_only: Option, + #[allow(unused)] options: Arguments, result_type: SnapshotChangeType, results: SnapshotCompareResult, } impl CompareMode { - pub fn new(options: Arguments, left: String, right: String, selection: Option, count_only: Option) -> CompareMode { + pub fn new( + options: Arguments, + left: String, + right: String, + selection: Option, + count_only: Option, + ) -> 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()); } } diff --git a/src/createmode.rs b/src/createmode.rs index 02dd145..bcf4843 100644 --- a/src/createmode.rs +++ b/src/createmode.rs @@ -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, diff --git a/src/main.rs b/src/main.rs index 901f717..f8a773f 100644 --- a/src/main.rs +++ b/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.."); diff --git a/src/options.rs b/src/options.rs index 4048778..bc0f56b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,6 +1,5 @@ use clap::{Parser, Subcommand}; - #[derive(Parser, Clone, Debug)] pub struct Arguments { #[command(subcommand)]