use colored::*;
use dialoguer::Confirm;
use crate::app::commands;
pub async fn delete(workspace_name: String) -> eyre::Result<()> {
let client = commands::anythingllm_client();
let workspace = client.get_workspace_by_name(&workspace_name).await?;
match client.get_workspace_by_name(&workspace_name).await {
Ok(_) => {}
_ => {
println!(
"{}",
format!("Workspace '{}' not unique. Exiting...", workspace_name).red()
);
return Ok(());
}
};
let confirm = Confirm::new()
.with_prompt(format!(
"Are you sure you want to delete workspace '{}'?",
workspace_name
))
.interact()?;
if !confirm {
println!("Cancelled");
return Ok(());
}
let result = client.delete_workspace_slug(&workspace.slug).await;
match result {
Ok(_) => {
println!("Deleted workspace '{}'", workspace_name);
}
Err(_) => {
println!("Error deleting workspace '{}'", workspace_name);
}
}
Ok(())
}
pub async fn delete_all() -> eyre::Result<()> {
let confirm = Confirm::new()
.with_prompt("Are you sure you want to delete all workspace?")
.interact()?;
if !confirm {
println!("Cancelled");
return Ok(());
}
let client = commands::anythingllm_client();
let workspaces = client.get_workspaces().await?;
for ws in workspaces {
let result = client.delete_workspace_slug(&ws.slug).await;
match result {
Ok(_) => {
println!("Deleted workspace '{}'", ws.name);
}
Err(_) => {
println!("Error deleting workspace '{}'", ws.name);
}
}
}
Ok(())
}