From 06ee41539473af5eb3730727e37b8459661998e9 Mon Sep 17 00:00:00 2001 From: jamesk Date: Fri, 29 Mar 2024 16:38:58 -0400 Subject: [PATCH 1/4] add_return_count_only_flag_on_compare --- src/comparemode.rs | 36 ++++++++++++++++++++++++++++-------- src/main.rs | 4 ++-- src/options.rs | 2 ++ 3 files changed, 32 insertions(+), 10 deletions(-) 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..641b8a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,9 @@ fn main() { println!("Creating snapshot.."); create.run() }, - Commands::Compare { left, right, selection } => { + Commands::Compare { left, right, selection, count_only } => { println!("Running snapshot comparison.."); - let mut compare = CompareMode::new(movable.clone(), left, right, selection); + 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..dec5ae0 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, long)] + count_only: Option, }, } From 7ebdcd1214806c59a42ea03ebd4ea201f426aa86 Mon Sep 17 00:00:00 2001 From: jamesk Date: Fri, 29 Mar 2024 16:45:08 -0400 Subject: [PATCH 2/4] . --- src/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.rs b/src/options.rs index dec5ae0..428d9cf 100644 --- a/src/options.rs +++ b/src/options.rs @@ -22,7 +22,7 @@ pub enum Commands { right: String, #[arg(short, long)] selection: Option, - #[arg(short, long)] + #[arg(short)] count_only: Option, }, } From b972314d5b893d8bce67a51ea73b957826d3d3aa Mon Sep 17 00:00:00 2001 From: jamesk Date: Fri, 29 Mar 2024 16:50:09 -0400 Subject: [PATCH 3/4] . --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 641b8a8..901f717 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,11 @@ fn main() { create.run() }, Commands::Compare { left, right, selection, count_only } => { - println!("Running snapshot comparison.."); + 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() } From acfe98210ea82e5272d5313758cd4cfa3709ba26 Mon Sep 17 00:00:00 2001 From: jamesk Date: Fri, 29 Mar 2024 16:51:43 -0400 Subject: [PATCH 4/4] . --- README.md | 1 + 1 file changed, 1 insertion(+) 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 ```