mirror of
https://github.com/Skallwar/suckit.git
synced 2026-09-10 07:16:19 -04:00
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:
parent
ffec62254d
commit
794d8ddd53
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue