initial commit
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ife1391ed23a1e7f388b1b5eca90b9ea76a6a6964
This commit is contained in:
commit
ef28bdaeb4
63 changed files with 17292 additions and 0 deletions
89
src/cli/commands/rm.rs
Normal file
89
src/cli/commands/rm.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
cli::RmArgs,
|
||||
error::{PakkerError, Result},
|
||||
model::LockFile,
|
||||
ui_utils::prompt_yes_no,
|
||||
};
|
||||
|
||||
pub async fn execute(
|
||||
args: RmArgs,
|
||||
lockfile_path: &Path,
|
||||
_config_path: &Path,
|
||||
) -> Result<()> {
|
||||
log::info!("Removing projects: {:?}", args.inputs);
|
||||
|
||||
// Load expects directory path, so get parent directory
|
||||
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
||||
let mut lockfile = LockFile::load(lockfile_dir)?;
|
||||
|
||||
let mut removed_count = 0;
|
||||
let mut removed_ids = Vec::new();
|
||||
let mut projects_to_remove = Vec::new();
|
||||
|
||||
// First, identify all projects to remove
|
||||
for input in &args.inputs {
|
||||
// Find project by various identifiers
|
||||
if let Some(project) = lockfile.projects.iter().find(|p| {
|
||||
p.pakku_id.as_deref() == Some(input)
|
||||
|| p.slug.values().any(|s| s == input)
|
||||
|| p.name.values().any(|n| n.eq_ignore_ascii_case(input))
|
||||
|| p.aliases.contains(input)
|
||||
}) {
|
||||
projects_to_remove.push(project.get_name());
|
||||
} else {
|
||||
log::warn!("Project not found: {input}");
|
||||
}
|
||||
}
|
||||
|
||||
if projects_to_remove.is_empty() {
|
||||
return Err(PakkerError::ProjectNotFound(
|
||||
"None of the specified projects found".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// Ask for confirmation unless --yes flag is provided
|
||||
if !args.yes {
|
||||
println!("The following projects will be removed:");
|
||||
for name in &projects_to_remove {
|
||||
println!(" - {name}");
|
||||
}
|
||||
|
||||
if !prompt_yes_no("Do you want to continue?", false)? {
|
||||
println!("Removal cancelled.");
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Now actually remove the projects
|
||||
for input in &args.inputs {
|
||||
if let Some(pos) = lockfile.projects.iter().position(|p| {
|
||||
p.pakku_id.as_deref() == Some(input)
|
||||
|| p.slug.values().any(|s| s == input)
|
||||
|| p.name.values().any(|n| n.eq_ignore_ascii_case(input))
|
||||
|| p.aliases.contains(input)
|
||||
}) {
|
||||
let project = lockfile.projects.remove(pos);
|
||||
log::info!("Removed: {}", project.get_name());
|
||||
if let Some(pakku_id) = project.pakku_id.clone() {
|
||||
removed_ids.push(pakku_id);
|
||||
}
|
||||
removed_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up pakku_links from all remaining projects
|
||||
for project in &mut lockfile.projects {
|
||||
project
|
||||
.pakku_links
|
||||
.retain(|link| !removed_ids.contains(link));
|
||||
}
|
||||
|
||||
// Save lockfile
|
||||
lockfile.save(lockfile_dir)?;
|
||||
|
||||
log::info!("Successfully removed {removed_count} project(s)");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue