Added support for dry running

This commit is contained in:
Sayantan Santra 2022-12-08 00:29:11 -06:00
parent e529ab2100
commit 89135740a8

View file

@ -56,7 +56,19 @@ fn main() {
api_key: api_key, api_key: api_key,
language: "en", language: "en",
}; };
let mut dry_run = false;
if filenames.contains(&"--dry-run".to_string()) {
println!("Doing a dry run.");
dry_run = true;
}
for filename in filenames { for filename in filenames {
if filename == "--dry-run".to_string() {
continue;
}
let metadata = Metadata::from(filename.as_str()).unwrap(); let metadata = Metadata::from(filename.as_str()).unwrap();
let results = tmdb let results = tmdb
.search() .search()
@ -112,9 +124,12 @@ fn main() {
println!("{} already has correct name.", filename); println!("{} already has correct name.", filename);
} else { } else {
println!("{} -> {}", filename, new_name); println!("{} -> {}", filename, new_name);
if dry_run == false {
println!("Doing the actual rename.");
fs::rename(filename, new_name).expect("Unable to rename file."); fs::rename(filename, new_name).expect("Unable to rename file.");
} }
} }
}
} }
fn display(movie: &MovieEntry) -> String { fn display(movie: &MovieEntry) -> String {