diff --git a/README.md b/README.md index 1b03876..9f6bf20 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Options: -l, --left -r, --right -s, --selection + -c [possible values: true, false] -h, --help Print help ``` diff --git a/src/comparemode.rs b/src/comparemode.rs index b8243c5..9715332 100644 --- a/src/comparemode.rs +++ b/src/comparemode.rs @@ -6,13 +6,14 @@ pub struct CompareMode { left: Snapshot, right: Snapshot, selection: Option, + count_only: Option, options: Arguments, result_type: SnapshotChangeType, results: SnapshotCompareResult, } impl CompareMode { - pub fn new(options: Arguments, left: String, right: String, selection: Option) -> CompareMode { + pub fn new(options: Arguments, left: String, right: String, selection: Option, count_only: Option) -> CompareMode { let left = import_snapshot(left); let right = import_snapshot(right); @@ -20,6 +21,7 @@ impl CompareMode { left, right, selection, + count_only, options, result_type: SnapshotChangeType::None, results: SnapshotCompareResult { @@ -47,18 +49,31 @@ impl CompareMode { self.results = results.1; self.result_type = results.0; + macro_rules! print_if_not_empty { + ($ret:expr, $co:expr) => {if let Some(count_only) = $co { + if count_only { + println!("{}", $ret.len()); + } else { + $ret.iter().for_each(|e| println!("{e}")); + println!("Created: {:?}", $ret.len()); + } + } else { + $ret.iter().for_each(|e| println!("{e}")); + println!("Created: {:?}", $ret.len()); + } + }; + } + + match selector { "created" => { - self.results.created.iter().for_each(|e| println!("{e}")); - println!("Created: {:?}", self.results.created.len()); + print_if_not_empty!(self.results.created, self.count_only); } "deleted" => { - self.results.deleted.iter().for_each(|e| println!("{e}")); - println!("Deleted: {:?}", self.results.deleted.len()); + print_if_not_empty!(self.results.deleted, self.count_only); } "changed" => { - self.results.changed.iter().for_each(|e| println!("{e}")); - println!("Changed: {:?}", self.results.changed.len()); + print_if_not_empty!(self.results.changed, self.count_only); } "none" => { println!("Created: {:?}", self.results.created.len()); @@ -72,13 +87,18 @@ impl CompareMode { } } } + fn return_ret(&self) { + + } } + + + #[cfg(test)] mod tests { use crate::comparemode::CompareMode; use crate::createmode::CreateMode; - use crate::syscompare::Comparer; use std::env; use std::fmt::format; diff --git a/src/main.rs b/src/main.rs index a6dbfd7..901f717 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,13 @@ fn main() { println!("Creating snapshot.."); create.run() }, - Commands::Compare { left, right, selection } => { - println!("Running snapshot comparison.."); - let mut compare = CompareMode::new(movable.clone(), left, right, selection); + Commands::Compare { left, right, selection, count_only } => { + if let Some(count_only) = count_only { + if !count_only { + println!("Running snapshot comparison.."); + } + } + let mut compare = CompareMode::new(movable.clone(), left, right, selection, count_only); compare.run() } }; diff --git a/src/options.rs b/src/options.rs index bdd60cc..428d9cf 100644 --- a/src/options.rs +++ b/src/options.rs @@ -22,5 +22,7 @@ pub enum Commands { right: String, #[arg(short, long)] selection: Option, + #[arg(short)] + count_only: Option, }, }