Skip to main content

cellos_ctl/cmd/
version.rs

1//! `cellctl version` — print version + (optionally) the server's reported version.
2
3use serde_json::Value;
4
5use crate::client::CellosClient;
6use crate::exit::CtlResult;
7
8pub async fn run(client: &CellosClient) -> CtlResult<()> {
9    println!("client: cellctl {}", env!("CARGO_PKG_VERSION"));
10
11    // Best-effort server version lookup; never fails the whole command if the
12    // server is unreachable — kubectl behaves the same way.
13    match client.get_json::<Value>("/v1/version").await {
14        Ok(v) => {
15            let svr = v
16                .get("version")
17                .and_then(|x| x.as_str())
18                .unwrap_or("unknown");
19            println!("server: cellos-server {svr} ({})", client.base_url());
20        }
21        Err(e) => {
22            eprintln!("server: <unreachable: {e}>");
23        }
24    }
25    Ok(())
26}