remove all panics
This commit is contained in:
parent
bf9d265bf3
commit
e792f1fce1
@ -70,7 +70,6 @@ impl Comparer for CompareMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
use std::process::exit;
|
||||||
use Fasching::{create_snapshot, export_snapshot};
|
use Fasching::{create_snapshot, export_snapshot};
|
||||||
use Fasching::hasher::HashType;
|
use Fasching::hasher::HashType;
|
||||||
use Fasching::hasher::HashType::BLAKE3;
|
use Fasching::hasher::HashType::BLAKE3;
|
||||||
use Fasching::snapshot::Snapshot;
|
use Fasching::snapshot::Snapshot;
|
||||||
|
use crate::print_help;
|
||||||
use crate::syscompare::Comparer;
|
use crate::syscompare::Comparer;
|
||||||
|
|
||||||
pub struct CreateMode {
|
pub struct CreateMode {
|
||||||
@ -14,7 +16,9 @@ pub struct CreateMode {
|
|||||||
impl CreateMode {
|
impl CreateMode {
|
||||||
pub fn new(args: Vec<String>, snapshot_path: String, root_path: String) -> CreateMode {
|
pub fn new(args: Vec<String>, snapshot_path: String, root_path: String) -> CreateMode {
|
||||||
if snapshot_path.replace("./", "").is_empty() {
|
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 bind = root_path.clone();
|
||||||
let rp = bind.as_str();
|
let rp = bind.as_str();
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -3,17 +3,18 @@ pub mod createmode;
|
|||||||
pub mod comparemode;
|
pub mod comparemode;
|
||||||
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
use std::process::exit;
|
||||||
use crate::syscompare::{SysCompareApp};
|
use crate::syscompare::{SysCompareApp};
|
||||||
use crate::syscompare::SysCompareMode::{Compare, Create};
|
use crate::syscompare::SysCompareMode::{Compare, Create};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
println!("{:#?}", args);
|
// println!("{:#?}", args); // testing
|
||||||
|
|
||||||
let app = match args.get(1) {
|
let app = match args.get(1) {
|
||||||
None => {
|
None => {
|
||||||
panic!("Missing Mode Argument");
|
print_help();
|
||||||
SysCompareApp::default()
|
exit(0);
|
||||||
}
|
}
|
||||||
Some(mode) => {
|
Some(mode) => {
|
||||||
// app mode
|
// app mode
|
||||||
@ -21,7 +22,11 @@ fn main() {
|
|||||||
let app_mode = match m {
|
let app_mode = match m {
|
||||||
"create" => { Create },
|
"create" => { Create },
|
||||||
"compare" => { Compare },
|
"compare" => { Compare },
|
||||||
_ => {panic!("Invalid MODE argument")}
|
_ => {
|
||||||
|
println!("Invalid MODE argument");
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SysCompareApp::new(app_mode, args)
|
SysCompareApp::new(app_mode, args)
|
||||||
@ -31,6 +36,11 @@ fn main() {
|
|||||||
app.run()
|
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)]
|
// #[cfg(test)]
|
||||||
// mod tests {
|
// mod tests {
|
||||||
// #[test]
|
// #[test]
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
use std::process::exit;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use Fasching::snapshot::Snapshot;
|
use Fasching::snapshot::Snapshot;
|
||||||
use crate::comparemode::CompareMode;
|
use crate::comparemode::CompareMode;
|
||||||
use crate::createmode::CreateMode;
|
use crate::createmode::CreateMode;
|
||||||
|
use crate::print_help;
|
||||||
|
|
||||||
pub enum SysCompareMode {
|
pub enum SysCompareMode {
|
||||||
Create,
|
Create,
|
||||||
@ -26,11 +28,19 @@ impl SysCompareApp {
|
|||||||
match self.mode {
|
match self.mode {
|
||||||
SysCompareMode::Create => {
|
SysCompareMode::Create => {
|
||||||
let snapshot_path = match self.args.get(2) {
|
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)}
|
Some(r) => {not_empty(r)}
|
||||||
};
|
};
|
||||||
let root_dir = match self.args.get(3) {
|
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)}
|
Some(r) => {not_empty(r)}
|
||||||
};
|
};
|
||||||
let mut create = CreateMode::new(self.args.clone(), snapshot_path.clone(), root_dir.clone());
|
let mut create = CreateMode::new(self.args.clone(), snapshot_path.clone(), root_dir.clone());
|
||||||
@ -38,11 +48,19 @@ impl SysCompareApp {
|
|||||||
}
|
}
|
||||||
SysCompareMode::Compare => {
|
SysCompareMode::Compare => {
|
||||||
let left = match self.args.get(2) {
|
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)}
|
Some(r) => {not_empty(r)}
|
||||||
};
|
};
|
||||||
let right = match self.args.get(3) {
|
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)}
|
Some(r) => {not_empty(r)}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,7 +73,9 @@ impl SysCompareApp {
|
|||||||
|
|
||||||
fn not_empty(r: &String) -> String {
|
fn not_empty(r: &String) -> String {
|
||||||
if r.replace("./", "").is_empty() {
|
if r.replace("./", "").is_empty() {
|
||||||
panic!("Specify input file name")
|
println!("Specify input file name");
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
r.to_string()
|
r.to_string()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user