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:
2025-11-18 18:19:38 -05:00
parent 89d273c38e
commit 8f142e07ba

View File

@@ -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 {
if args.no_delete {
println!(" [~] SKIP DELETE: {} (--no-delete active)", name);
} else {
println!(" [-] DELETE: {}", name); println!(" [-] DELETE: {}", name);
} }
}
println!("----------------------"); println!("----------------------");
if args.no_delete {
println!(
"Summary: {} to add, {} to delete (SKIPPED), {} unchanged.",
to_add.len(),
to_delete.len(),
to_keep.len()
);
} else {
println!( println!(
"Summary: {} to add, {} to delete, {} unchanged.", "Summary: {} to add, {} to delete, {} unchanged.",
to_add.len(), to_add.len(),
to_delete.len(), to_delete.len(),
to_keep.len() to_keep.len()
); );
}
if to_add.is_empty() && to_delete.is_empty() { // If nothing to add, and (deletes are empty OR we are skipping deletes), then done.
info!("Sync complete. No changes detected."); if to_add.is_empty() && (to_delete.is_empty() || args.no_delete) {
info!("Sync complete. No changes to apply.");
return Ok(()); return Ok(());
} }
@@ -197,6 +216,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
// Deletions // Deletions
if !args.no_delete {
for name in to_delete { for name in to_delete {
info!("Deleting {}...", name); info!("Deleting {}...", name);
match delete_repo(&http_client, &config, &owner_name, &name).await { match delete_repo(&http_client, &config, &owner_name, &name).await {
@@ -204,6 +224,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e) => error!("Failed to delete {}: {}", name, e), 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.");
Ok(()) Ok(())