Merge pull request #4 from helloimalemur/count_only_flag
add_return_count_only_flag_on_compare
This commit is contained in:
commit
02c6674fa6
@ -37,6 +37,7 @@ Options:
|
||||
-l, --left <LEFT>
|
||||
-r, --right <RIGHT>
|
||||
-s, --selection <SELECTION>
|
||||
-c <COUNT_ONLY> [possible values: true, false]
|
||||
-h, --help Print help
|
||||
```
|
||||
|
||||
|
@ -6,13 +6,14 @@ pub struct CompareMode {
|
||||
left: Snapshot,
|
||||
right: Snapshot,
|
||||
selection: Option<String>,
|
||||
count_only: Option<bool>,
|
||||
options: Arguments,
|
||||
result_type: SnapshotChangeType,
|
||||
results: SnapshotCompareResult,
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
|
10
src/main.rs
10
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()
|
||||
}
|
||||
};
|
||||
|
@ -22,5 +22,7 @@ pub enum Commands {
|
||||
right: String,
|
||||
#[arg(short, long)]
|
||||
selection: Option<String>,
|
||||
#[arg(short)]
|
||||
count_only: Option<bool>,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user