refactoring output option file already exists #713
This commit is contained in:
@@ -480,6 +480,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Check file path exist. If path is existed, output alert message.
|
||||
pub fn check_file_expect_not_exist(path: &Path, exist_alert_str: String) -> bool {
|
||||
let ret = path.exists();
|
||||
if ret {
|
||||
AlertMessage::alert(&exist_alert_str).ok();
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -219,20 +219,21 @@ impl App {
|
||||
pivot_key_unions.iter().for_each(|(key, _)| {
|
||||
let keywords_file_name =
|
||||
csv_path.as_path().display().to_string() + "-" + key + ".txt";
|
||||
if Path::new(&keywords_file_name).exists() {
|
||||
AlertMessage::alert(&format!(
|
||||
utils::check_file_expect_not_exist(
|
||||
Path::new(&keywords_file_name),
|
||||
format!(
|
||||
" The file {} already exists. Please specify a different filename.",
|
||||
&keywords_file_name
|
||||
))
|
||||
.ok();
|
||||
}
|
||||
),
|
||||
);
|
||||
});
|
||||
if csv_path.exists() {
|
||||
AlertMessage::alert(&format!(
|
||||
if utils::check_file_expect_not_exist(
|
||||
csv_path,
|
||||
format!(
|
||||
" The file {} already exists. Please specify a different filename.",
|
||||
csv_path.as_os_str().to_str().unwrap()
|
||||
))
|
||||
.ok();
|
||||
),
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -263,14 +264,15 @@ impl App {
|
||||
println!();
|
||||
}
|
||||
|
||||
if let Some(path) = &configs::CONFIG.read().unwrap().args.html_report {
|
||||
if let Some(html_path) = &configs::CONFIG.read().unwrap().args.html_report {
|
||||
// if already exists same html report file. output alert message and exit
|
||||
if path.exists() {
|
||||
AlertMessage::alert(&format!(
|
||||
if utils::check_file_expect_not_exist(
|
||||
html_path.as_path(),
|
||||
format!(
|
||||
" The file {} already exists. Please specify a different filename.",
|
||||
path.to_str().unwrap()
|
||||
))
|
||||
.ok();
|
||||
html_path.to_str().unwrap()
|
||||
),
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user