feat(cli): surface the waiting state and its condition
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ pub async fn status(paths: Paths, name: String) -> Result<i32> {
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(info) = &d.wait_for {
|
||||
print!("{}", format::wait_line(info));
|
||||
}
|
||||
|
||||
println!("{:#?}", d);
|
||||
|
||||
Ok(0)
|
||||
|
||||
@@ -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<StatusDetail, ApiError> {
|
||||
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(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user