Add a flag to not run deletes, meaning non destructive. Gemini 3.0
Prompt; ``` Great! Now can you add a new flag which says to not delete projects. Basically, I want an option to run the tool in a non destructive fashion. ```
This commit is contained in:
51
src/main.rs
51
src/main.rs
@@ -22,6 +22,10 @@ struct Args {
|
|||||||
/// Skip the interactive confirmation prompt.
|
/// Skip the interactive confirmation prompt.
|
||||||
#[clap(long, default_value_t = false)]
|
#[clap(long, default_value_t = false)]
|
||||||
no_confirm: bool,
|
no_confirm: bool,
|
||||||
|
|
||||||
|
/// Do not delete repositories from Gitea.
|
||||||
|
#[clap(long, default_value_t = false)]
|
||||||
|
no_delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
@@ -145,18 +149,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!(" [+] ADD: {} (Source: {})", name, url);
|
println!(" [+] ADD: {} (Source: {})", name, url);
|
||||||
}
|
}
|
||||||
for name in &to_delete {
|
for name in &to_delete {
|
||||||
println!(" [-] DELETE: {}", name);
|
if args.no_delete {
|
||||||
|
println!(" [~] SKIP DELETE: {} (--no-delete active)", name);
|
||||||
|
} else {
|
||||||
|
println!(" [-] DELETE: {}", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println!("----------------------");
|
println!("----------------------");
|
||||||
println!(
|
|
||||||
"Summary: {} to add, {} to delete, {} unchanged.",
|
|
||||||
to_add.len(),
|
|
||||||
to_delete.len(),
|
|
||||||
to_keep.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if to_add.is_empty() && to_delete.is_empty() {
|
if args.no_delete {
|
||||||
info!("Sync complete. No changes detected.");
|
println!(
|
||||||
|
"Summary: {} to add, {} to delete (SKIPPED), {} unchanged.",
|
||||||
|
to_add.len(),
|
||||||
|
to_delete.len(),
|
||||||
|
to_keep.len()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Summary: {} to add, {} to delete, {} unchanged.",
|
||||||
|
to_add.len(),
|
||||||
|
to_delete.len(),
|
||||||
|
to_keep.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing to add, and (deletes are empty OR we are skipping deletes), then done.
|
||||||
|
if to_add.is_empty() && (to_delete.is_empty() || args.no_delete) {
|
||||||
|
info!("Sync complete. No changes to apply.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,12 +216,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deletions
|
// Deletions
|
||||||
for name in to_delete {
|
if !args.no_delete {
|
||||||
info!("Deleting {}...", name);
|
for name in to_delete {
|
||||||
match delete_repo(&http_client, &config, &owner_name, &name).await {
|
info!("Deleting {}...", name);
|
||||||
Ok(_) => info!("Successfully deleted {}", name),
|
match delete_repo(&http_client, &config, &owner_name, &name).await {
|
||||||
Err(e) => error!("Failed to delete {}: {}", name, e),
|
Ok(_) => info!("Successfully deleted {}", name),
|
||||||
|
Err(e) => error!("Failed to delete {}: {}", name, e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if !to_delete.is_empty() {
|
||||||
|
info!("Skipping deletions due to --no-delete flag.");
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Process completed.");
|
info!("Process completed.");
|
||||||
|
|||||||
Reference in New Issue
Block a user