cli: implement rm --all to remove all projects

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9776c31b90336bf33475adb1e36dc3a36a6a6964
This commit is contained in:
raf 2026-02-07 13:25:37 +03:00
commit 6648de9971
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -12,18 +12,46 @@ pub async fn execute(
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)?;
// Determine which projects to remove
let inputs: Vec<String> = if args.all {
log::info!("Removing all projects from lockfile");
lockfile
.projects
.iter()
.filter_map(|p| {
p.pakku_id
.clone()
.or_else(|| p.slug.values().next().cloned())
})
.collect()
} else {
args.inputs.clone()
};
if inputs.is_empty() {
return if args.all {
Err(PakkerError::ProjectNotFound(
"No projects found in lockfile".to_string(),
))
} else {
Err(PakkerError::ProjectNotFound(
"No projects specified".to_string(),
))
};
}
log::info!("Removing projects: {:?}", inputs);
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 {
for input in &inputs {
// Find project by various identifiers
if let Some(project) = lockfile.projects.iter().find(|p| {
p.pakku_id.as_deref() == Some(input)
@ -32,7 +60,7 @@ pub async fn execute(
|| p.aliases.contains(input)
}) {
projects_to_remove.push(project.get_name());
} else {
} else if !args.all {
log::warn!("Project not found: {input}");
}
}
@ -43,7 +71,8 @@ pub async fn execute(
));
}
// Ask for confirmation unless --yes flag is provided
// Ask for confirmation unless --yes flag is provided or --all with no
// projects
if !args.yes {
println!("The following projects will be removed:");
for name in &projects_to_remove {
@ -57,7 +86,7 @@ pub async fn execute(
}
// Now actually remove the projects
for input in &args.inputs {
for input in &inputs {
if let Some(pos) = lockfile.projects.iter().position(|p| {
p.pakku_id.as_deref() == Some(input)
|| p.slug.values().any(|s| s == input)