remove all panics

This commit is contained in:
jamesk 2024-03-25 16:49:12 -04:00
parent bf9d265bf3
commit e792f1fce1
4 changed files with 44 additions and 11 deletions

View File

@ -70,7 +70,6 @@ impl Comparer for CompareMode {
}
}
#[cfg(test)]
mod tests {
use std::env;

View File

@ -1,7 +1,9 @@
use std::process::exit;
use Fasching::{create_snapshot, export_snapshot};
use Fasching::hasher::HashType;
use Fasching::hasher::HashType::BLAKE3;
use Fasching::snapshot::Snapshot;
use crate::print_help;
use crate::syscompare::Comparer;
pub struct CreateMode {
@ -14,7 +16,9 @@ pub struct CreateMode {
impl CreateMode {
pub fn new(args: Vec<String>, snapshot_path: String, root_path: String) -> CreateMode {
if snapshot_path.replace("./", "").is_empty() {
panic!("Specify output file name")
println!("Specify output file name");
print_help();
exit(0);
}
let bind = root_path.clone();
let rp = bind.as_str();

View File

@ -3,17 +3,18 @@ pub mod createmode;
pub mod comparemode;
use std::env::args;
use std::process::exit;
use crate::syscompare::{SysCompareApp};
use crate::syscompare::SysCompareMode::{Compare, Create};
fn main() {
let args: Vec<String> = args().collect();
println!("{:#?}", args);
// println!("{:#?}", args); // testing
let app = match args.get(1) {
None => {
panic!("Missing Mode Argument");
SysCompareApp::default()
print_help();
exit(0);
}
Some(mode) => {
// app mode
@ -21,7 +22,11 @@ fn main() {
let app_mode = match m {
"create" => { Create },
"compare" => { Compare },
_ => {panic!("Invalid MODE argument")}
_ => {
println!("Invalid MODE argument");
print_help();
exit(0);
}
};
SysCompareApp::new(app_mode, args)
@ -31,6 +36,11 @@ fn main() {
app.run()
}
pub fn print_help() {
println!("### Create Snapshot\n## ./sys-compare create [snapshot] [root_dir]");
println!("### Compare Snapshots\n## ./sys-compare compare [.snap] [.snap] [created]|[deleted]|[changed]");
}
// #[cfg(test)]
// mod tests {
// #[test]

View File

@ -1,9 +1,11 @@
use std::collections::HashMap;
use std::env::args;
use std::process::exit;
use std::sync::{Arc, Mutex};
use Fasching::snapshot::Snapshot;
use crate::comparemode::CompareMode;
use crate::createmode::CreateMode;
use crate::print_help;
pub enum SysCompareMode {
Create,
@ -26,11 +28,19 @@ impl SysCompareApp {
match self.mode {
SysCompareMode::Create => {
let snapshot_path = match self.args.get(2) {
None => {panic!("Missing hash dir path as second argument")}
None => {
println!("Missing hash dir path as second argument");
print_help();
exit(0);
}
Some(r) => {not_empty(r)}
};
let root_dir = match self.args.get(3) {
None => {panic!("Missing hash dir path as second argument")}
None => {
println!("Missing hash dir path as second argument");
print_help();
exit(0);
}
Some(r) => {not_empty(r)}
};
let mut create = CreateMode::new(self.args.clone(), snapshot_path.clone(), root_dir.clone());
@ -38,11 +48,19 @@ impl SysCompareApp {
}
SysCompareMode::Compare => {
let left = match self.args.get(2) {
None => {panic!("Missing hash dir path as second argument")}
None => {
println!("Missing hash dir path as second argument");
print_help();
exit(0);
}
Some(r) => {not_empty(r)}
};
let right = match self.args.get(3) {
None => {panic!("Missing output path as third argument")}
None => {
println!("Missing output path as third argument");
print_help();
exit(0);
}
Some(r) => {not_empty(r)}
};
@ -55,7 +73,9 @@ impl SysCompareApp {
fn not_empty(r: &String) -> String {
if r.replace("./", "").is_empty() {
panic!("Specify input file name")
println!("Specify input file name");
print_help();
exit(0);
} else {
r.to_string()
}