Skip to main content

xianyun_cli/commands/
down.rs

1//! `caproni down` (alias `stop`): stop the cluster.
2//!
3//! Port of Go's `cmd/down` package.
4
5use anyhow::Context as _;
6use clap::Args;
7use xianyun_core::config::caproni::load_from_context;
8use xianyun_core::config::global::Context;
9
10#[derive(Args, Debug)]
11pub struct DownArgs {}
12
13pub fn run(_args: &DownArgs, ctx: &Context) -> anyhow::Result<()> {
14    run_stop(ctx)
15}
16
17/// Port of `down.runStop`: loads the configuration, resolves the cluster
18/// manager for its configured driver, and stops the cluster.
19pub fn run_stop(ctx: &Context) -> anyhow::Result<()> {
20    crate::drivers::ensure_registered();
21
22    let container = load_from_context(ctx).context("loading configuration")?;
23
24    let manager = xianyun_cluster::registry::new_manager(
25        container.caproni.cluster.clone(),
26        container.global.profile_name.clone(),
27    )
28    .context("creating cluster manager")?;
29
30    manager.stop().context("stopping cluster")?;
31
32    Ok(())
33}