use cuenv_events::{emit_service_stopped, emit_service_stopping, emit_stdout};
pub struct DownOptions {
pub path: String,
pub package: String,
pub services: Vec<String>,
}
pub fn execute_down(options: &DownOptions) -> cuenv_core::Result<String> {
emit_stdout!(format!(
"cuenv down: tearing down services in {} (package: {})",
options.path, options.package
));
if options.services.is_empty() {
emit_stdout!("cuenv down: no service names specified — would tear down all services");
} else {
for svc in options.services.iter().rev() {
emit_service_stopping!(svc);
emit_service_stopped!(svc, Some(0));
}
}
Ok("cuenv down: stub complete".to_string())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_down_options_default() {
let options = DownOptions {
path: ".".to_string(),
package: "cuenv".to_string(),
services: vec![],
};
assert_eq!(options.path, ".");
assert_eq!(options.package, "cuenv");
assert!(options.services.is_empty());
}
#[test]
fn test_execute_down_stub_no_services() {
let options = DownOptions {
path: ".".to_string(),
package: "cuenv".to_string(),
services: vec![],
};
let result = execute_down(&options);
assert!(result.is_ok());
assert!(result.as_ref().is_ok_and(|s| s.contains("stub complete")));
}
#[test]
fn test_execute_down_stub_with_services() {
let options = DownOptions {
path: ".".to_string(),
package: "cuenv".to_string(),
services: vec!["db".to_string(), "api".to_string()],
};
let result = execute_down(&options);
assert!(result.is_ok());
}
}