Add dry run flag (#95)

Add --dry-run flag to stop files from being saved, as mentioned in
https://github.com/Skallwar/suckit/issues/94
This commit is contained in:
Jaslo Ziska 2020-10-03 22:36:35 +02:00 committed by GitHub
parent ffec62254d
commit 794d8ddd53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -102,6 +102,10 @@ pub struct Args {
/// Decides if we should bail out on download error (like, too many redirects)
#[structopt(short, long, help = "Flag to enable or disable exit on error")]
pub continue_on_error: bool,
/// If set, run without saving anything to the disk
#[structopt(long, help = "Do everything without saving the files to the disk")]
pub dry_run: bool,
}
impl Args {

View file

@ -131,7 +131,8 @@ impl Scraper {
let path_map = scraper.path_map.lock().unwrap();
let path = path_map.get(url.as_str()).unwrap();
if !scraper.args.exclude.is_match(url.as_str())
if !scraper.args.dry_run
&& !scraper.args.exclude.is_match(url.as_str())
&& scraper.args.include.is_match(url.as_str())
{
match response.filename {
@ -253,6 +254,7 @@ mod tests {
include: Regex::new("jpg").unwrap(),
exclude: Regex::new("png").unwrap(),
continue_on_error: true,
dry_run: false,
};
let _ = Scraper::new(args);
@ -273,6 +275,7 @@ mod tests {
include: Regex::new("jpg").unwrap(),
exclude: Regex::new("png").unwrap(),
continue_on_error: true,
dry_run: false,
};
let _ = Scraper::new(args);