Skip to main content

xianyun_cli/commands/
status.rs

1//! `caproni status`: show the status of all services.
2//!
3//! Port of Go's `cmd/status` package.
4
5use anyhow::Context as _;
6use clap::Args;
7use xianyun_cluster::driver::State;
8use xianyun_core::config::caproni::load_from_context;
9use xianyun_core::config::global::Context;
10
11#[derive(Args, Debug)]
12pub struct StatusArgs {}
13
14pub fn run(_args: &StatusArgs, ctx: &Context) -> anyhow::Result<()> {
15    run_status(ctx)
16}
17
18/// Port of `status.runStatus`: loads the configuration, resolves the
19/// cluster manager for its configured driver, and reports its status.
20///
21/// Reloader status reporting (the `pterm` table Go renders when the
22/// cluster is ready and reloaders are configured) needs a real kubectl
23/// backend and reloader managers, neither of which exist in this
24/// worktree's sibling crates yet, so it is not ported here: when there are
25/// no reloaders configured (as in every non-integration test) Go's
26/// `runStatus` returns before ever touching them, which is exactly the
27/// path this port covers.
28pub fn run_status(ctx: &Context) -> anyhow::Result<()> {
29    crate::drivers::ensure_registered();
30
31    let container = load_from_context(ctx).context("loading configuration")?;
32
33    let manager = xianyun_cluster::registry::new_manager(
34        container.caproni.cluster.clone(),
35        container.global.profile_name.clone(),
36    )
37    .context("creating cluster manager")?;
38
39    let status = manager.status().context("getting cluster status")?;
40
41    let reloader_count = container
42        .caproni
43        .reloaders
44        .as_ref()
45        .map_or(0, xianyun_core::orderedmap::OrderedMap::len);
46
47    if status.state != Some(State::Ready) || reloader_count == 0 {
48        return Ok(());
49    }
50
51    anyhow::bail!(
52        "reporting reloader status requires a real kubectl backend and reloader managers, \
53        neither of which is implemented in this worktree yet"
54    );
55}