add_return_count_only_flag_on_compare
This commit is contained in:
parent
ddb81ecde0
commit
06ee415394
@ -6,13 +6,14 @@ pub struct CompareMode {
|
|||||||
left: Snapshot,
|
left: Snapshot,
|
||||||
right: Snapshot,
|
right: Snapshot,
|
||||||
selection: Option<String>,
|
selection: Option<String>,
|
||||||
|
count_only: Option<bool>,
|
||||||
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>) -> CompareMode {
|
pub fn new(options: Arguments, left: String, right: String, selection: Option<String>, count_only: Option<bool>) -> CompareMode {
|
||||||
let left = import_snapshot(left);
|
let left = import_snapshot(left);
|
||||||
let right = import_snapshot(right);
|
let right = import_snapshot(right);
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ impl CompareMode {
|
|||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
selection,
|
selection,
|
||||||
|
count_only,
|
||||||
options,
|
options,
|
||||||
result_type: SnapshotChangeType::None,
|
result_type: SnapshotChangeType::None,
|
||||||
results: SnapshotCompareResult {
|
results: SnapshotCompareResult {
|
||||||
@ -47,18 +49,31 @@ impl CompareMode {
|
|||||||
self.results = results.1;
|
self.results = results.1;
|
||||||
self.result_type = results.0;
|
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 {
|
match selector {
|
||||||
"created" => {
|
"created" => {
|
||||||
self.results.created.iter().for_each(|e| println!("{e}"));
|
print_if_not_empty!(self.results.created, self.count_only);
|
||||||
println!("Created: {:?}", self.results.created.len());
|
|
||||||
}
|
}
|
||||||
"deleted" => {
|
"deleted" => {
|
||||||
self.results.deleted.iter().for_each(|e| println!("{e}"));
|
print_if_not_empty!(self.results.deleted, self.count_only);
|
||||||
println!("Deleted: {:?}", self.results.deleted.len());
|
|
||||||
}
|
}
|
||||||
"changed" => {
|
"changed" => {
|
||||||
self.results.changed.iter().for_each(|e| println!("{e}"));
|
print_if_not_empty!(self.results.changed, self.count_only);
|
||||||
println!("Changed: {:?}", self.results.changed.len());
|
|
||||||
}
|
}
|
||||||
"none" => {
|
"none" => {
|
||||||
println!("Created: {:?}", self.results.created.len());
|
println!("Created: {:?}", self.results.created.len());
|
||||||
@ -72,13 +87,18 @@ impl CompareMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn return_ret(&self) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::comparemode::CompareMode;
|
use crate::comparemode::CompareMode;
|
||||||
use crate::createmode::CreateMode;
|
use crate::createmode::CreateMode;
|
||||||
use crate::syscompare::Comparer;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt::format;
|
use std::fmt::format;
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ fn main() {
|
|||||||
println!("Creating snapshot..");
|
println!("Creating snapshot..");
|
||||||
create.run()
|
create.run()
|
||||||
},
|
},
|
||||||
Commands::Compare { left, right, selection } => {
|
Commands::Compare { left, right, selection, count_only } => {
|
||||||
println!("Running snapshot comparison..");
|
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()
|
compare.run()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,5 +22,7 @@ pub enum Commands {
|
|||||||
right: String,
|
right: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
selection: Option<String>,
|
selection: Option<String>,
|
||||||
|
#[arg(short, long)]
|
||||||
|
count_only: Option<bool>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user