cli: implement rm --all to remove all projects
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I9776c31b90336bf33475adb1e36dc3a36a6a6964
This commit is contained in:
parent
a50657bad5
commit
6648de9971
1 changed files with 35 additions and 6 deletions
|
|
@ -12,18 +12,46 @@ pub async fn execute(
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
_config_path: &Path,
|
_config_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
log::info!("Removing projects: {:?}", args.inputs);
|
|
||||||
|
|
||||||
// Load expects directory path, so get parent directory
|
// Load expects directory path, so get parent directory
|
||||||
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
||||||
let mut lockfile = LockFile::load(lockfile_dir)?;
|
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_count = 0;
|
||||||
let mut removed_ids = Vec::new();
|
let mut removed_ids = Vec::new();
|
||||||
let mut projects_to_remove = Vec::new();
|
let mut projects_to_remove = Vec::new();
|
||||||
|
|
||||||
// First, identify all projects to remove
|
// First, identify all projects to remove
|
||||||
for input in &args.inputs {
|
for input in &inputs {
|
||||||
// Find project by various identifiers
|
// Find project by various identifiers
|
||||||
if let Some(project) = lockfile.projects.iter().find(|p| {
|
if let Some(project) = lockfile.projects.iter().find(|p| {
|
||||||
p.pakku_id.as_deref() == Some(input)
|
p.pakku_id.as_deref() == Some(input)
|
||||||
|
|
@ -32,7 +60,7 @@ pub async fn execute(
|
||||||
|| p.aliases.contains(input)
|
|| p.aliases.contains(input)
|
||||||
}) {
|
}) {
|
||||||
projects_to_remove.push(project.get_name());
|
projects_to_remove.push(project.get_name());
|
||||||
} else {
|
} else if !args.all {
|
||||||
log::warn!("Project not found: {input}");
|
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 {
|
if !args.yes {
|
||||||
println!("The following projects will be removed:");
|
println!("The following projects will be removed:");
|
||||||
for name in &projects_to_remove {
|
for name in &projects_to_remove {
|
||||||
|
|
@ -57,7 +86,7 @@ pub async fn execute(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now actually remove the projects
|
// Now actually remove the projects
|
||||||
for input in &args.inputs {
|
for input in &inputs {
|
||||||
if let Some(pos) = lockfile.projects.iter().position(|p| {
|
if let Some(pos) = lockfile.projects.iter().position(|p| {
|
||||||
p.pakku_id.as_deref() == Some(input)
|
p.pakku_id.as_deref() == Some(input)
|
||||||
|| p.slug.values().any(|s| s == input)
|
|| p.slug.values().any(|s| s == input)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue