From 2b84f1d1e0c3f846aa863808af3295894bef7bde Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Fri, 7 Aug 2026 15:50:37 +0200 Subject: [PATCH] feat(cli): surface the waiting state and its condition --- crates/xy/src/cli/format.rs | 50 +++++++++++++++++++++++++++++++- crates/xy/src/cli/mod.rs | 4 +++ crates/xy/src/daemon/handlers.rs | 8 +++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/crates/xy/src/cli/format.rs b/crates/xy/src/cli/format.rs index 851a81c..10aacaf 100644 --- a/crates/xy/src/cli/format.rs +++ b/crates/xy/src/cli/format.rs @@ -1,4 +1,4 @@ -use xy_protocol::rpc::ServerSummary; +use xy_protocol::rpc::{ServerSummary, WaitInfo}; pub fn list_table(rows: &[ServerSummary]) -> String { let mut out = String::new(); @@ -25,3 +25,51 @@ pub fn list_table(rows: &[ServerSummary]) -> String { out } + +pub(crate) fn wait_line(info: &WaitInfo) -> String { + format!( + " wait-for: {}\n {}s elapsed, timeout {}s\n", + info.description, info.elapsed_secs, info.timeout_secs + ) +} + +#[cfg(test)] +mod tests { + use super::*; + use xy_protocol::{ServerState, rpc::WaitInfo}; + + #[test] + fn list_renders_the_waiting_state() { + let rows = vec![ServerSummary { + name: "gitea".to_string(), + state: ServerState::Waiting, + pid: None, + port: 8181, + uptime_secs: None, + restart_count: 0, + last_exit: None, + }]; + + let out = list_table(&rows); + + assert!(out.contains("waiting"), "got: {out}"); + } + + #[test] + fn status_renders_the_wait_condition_and_elapsed() { + let info = WaitInfo { + description: "path /Users/me/.orbstack/run/docker.sock".to_string(), + elapsed_secs: 43, + timeout_secs: 120, + }; + + let out = wait_line(&info); + + assert!( + out.contains("path /Users/me/.orbstack/run/docker.sock"), + "got: {out}" + ); + assert!(out.contains("43s elapsed"), "got: {out}"); + assert!(out.contains("timeout 120s"), "got: {out}"); + } +} diff --git a/crates/xy/src/cli/mod.rs b/crates/xy/src/cli/mod.rs index a8bfdf1..f738133 100644 --- a/crates/xy/src/cli/mod.rs +++ b/crates/xy/src/cli/mod.rs @@ -58,6 +58,10 @@ pub async fn status(paths: Paths, name: String) -> Result { } }; + if let Some(info) = &d.wait_for { + print!("{}", format::wait_line(info)); + } + println!("{:#?}", d); Ok(0) diff --git a/crates/xy/src/daemon/handlers.rs b/crates/xy/src/daemon/handlers.rs index c81296e..238a1ad 100644 --- a/crates/xy/src/daemon/handlers.rs +++ b/crates/xy/src/daemon/handlers.rs @@ -11,7 +11,7 @@ use xy_ipc::envelope::{Incoming, Request, Response, err_response, ok_response}; use xy_protocol::RpcErrorCode; use xy_protocol::rpc::{ LogEnd, LogLine, LogsCancelParams, LogsParams, LogsSubscribed, NameOrAll, RestartResult, - ServerSummary, StartResult, StatusDetail, StopResult, methods, notifications, + ServerSummary, StartResult, StatusDetail, StopResult, WaitInfo, methods, notifications, }; use xy_supervisor::supervisor::{StartAck, StopAck, SupervisorCmd}; @@ -200,7 +200,11 @@ async fn status(reg: &Registry, name: &str) -> Result { last_exit: s.last_exit, }, recent_transitions: Vec::new(), - wait_for: None, + wait_for: s.waiting.as_ref().map(|w| WaitInfo { + description: w.description.clone(), + elapsed_secs: w.started_at.elapsed().as_secs(), + timeout_secs: w.timeout.as_secs(), + }), }) }