feat(06-04): implement --simulate dry-run mode
- Added simulate mode check before download loop - When --simulate is set, prints URLs that would be downloaded but skips actual download - Added destination directory creation if it doesn't exist - Uses --destination argument for download location
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -195,7 +195,7 @@ fn main() {
|
||||
// Create a simple destination path based on the URL
|
||||
// In a full implementation, this would use path templates
|
||||
let filename = format!("{}.download", j + 1);
|
||||
let destination = PathBuf::from(".").join(&filename);
|
||||
let destination = args.destination.clone().unwrap_or_else(|| PathBuf::from(".")).join(&filename);
|
||||
|
||||
let mut values = HashMap::new();
|
||||
values.insert("num".to_string(), serde_json::json!(j + 1));
|
||||
@@ -212,6 +212,27 @@ fn main() {
|
||||
}
|
||||
total_items += items.len();
|
||||
|
||||
// Check for simulate/dry-run mode
|
||||
if args.simulate {
|
||||
log::info!("SIMULATE MODE: URLs extracted but not downloaded");
|
||||
// Still print what would be downloaded
|
||||
for item in &download_items {
|
||||
println!("[SIMULATE] Would download: {} -> {:?}", item.url, item.destination);
|
||||
}
|
||||
continue; // Skip actual download
|
||||
}
|
||||
|
||||
// Ensure destination directory exists
|
||||
if let Some(ref dest) = args.destination {
|
||||
if !dest.exists() {
|
||||
if let Err(e) = std::fs::create_dir_all(dest) {
|
||||
log::warn!("Failed to create destination directory {:?}: {}", dest, e);
|
||||
} else {
|
||||
log::info!("Created destination directory: {:?}", dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actually download the files using DownloadWorker
|
||||
if !download_items.is_empty() {
|
||||
let worker = match DownloadWorker::new(jobs) {
|
||||
|
||||
Reference in New Issue
Block a user