46 lines
1.2 KiB
Rust

use colored::*;
use crate::process::ProcessManager;
pub async fn handle(service: Option<String>) -> Result<(), Box<dyn std::error::Error>> {
let services = vec![
("user_service", 13001),
("api", 8001),
("api_gateway", 8000),
];
if let Some(service_name) = service {
print!("⏹️ Stopping {}... ", service_name.bold());
match ProcessManager::stop_service(&service_name).await {
Ok(_) => {
println!("{}", "".green());
}
Err(e) => {
println!("{}", format!("{}", e).red());
}
}
} else {
println!(
"{}",
"⏹️ Stopping all services...".bold().red()
);
println!();
for (name, _) in &services {
print!(" {} {}... ", "".red(), name.bold());
match ProcessManager::stop_service(name).await {
Ok(_) => {
println!("{}", "".green());
}
Err(e) => {
println!("{}", format!("{}", e).red());
}
}
}
println!();
println!("{}", "✅ All services stopped".green().bold());
}
Ok(())
}