From 043b804c44665b07bd503fdad896bbe0a29311a0 Mon Sep 17 00:00:00 2001 From: Can Celik Date: Thu, 10 Sep 2026 23:33:27 +0300 Subject: feat: route cli commands to saved ssh machines (#3918) --- src/cli.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index d4ae2f84..154e0c99 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,6 +37,7 @@ mod server_not_running; mod spec; mod status; mod tab; +mod target; mod workspace; mod worktree; @@ -93,6 +94,10 @@ pub(super) fn print_read_response(response: &serde_json::Value) -> std::io::Resu Ok(0) } +pub(crate) fn maybe_run_machine(args: &[String]) -> Option> { + target::maybe_run(args) +} + pub fn maybe_run(args: &[String]) -> std::io::Result { let Some(command) = args.get(1).map(|arg| arg.as_str()) else { return Ok(CommandOutcome::NotCli); @@ -762,7 +767,7 @@ pub(super) fn send_ok_request(method: Method) -> std::io::Result { } pub(super) fn send_request(request: &Request) -> std::io::Result { - let client = ApiClient::local(); + let client = target::api_client()?; ensure_server_protocol_compatible(&client, &request.id)?; client .request_value(request) @@ -770,7 +775,7 @@ pub(super) fn send_request(request: &Request) -> std::io::Result std::io::Result { - let client = ApiClient::local(); + let client = target::api_client()?; client .request_value(request) .map_err(|err| map_server_not_running_or_io(err, &request.id, &client)) @@ -783,11 +788,9 @@ fn ensure_server_protocol_compatible(client: &ApiClient, request_id: &str) -> st let server_protocol = status .protocol .ok_or_else(|| std::io::Error::other("server ping did not include a protocol version"))?; - let Some(response) = protocol_guard::mismatch_response( - request_id, - server_protocol, - &crate::session::active_restart_after_update_guidance(), - ) else { + let Some(response) = + protocol_guard::mismatch_response(request_id, server_protocol, &target::restart_guidance()) + else { return Ok(()); }; @@ -834,6 +837,9 @@ fn map_server_not_running_or_io( request_id: &str, client: &ApiClient, ) -> std::io::Error { + if target::is_remote() { + return target::remote_error(api_client_error_to_io(err)); + } match err { ApiClientError::Io(io_err) if server_not_running_error(&io_err) => { server_not_running::reported_error(server_not_running::response( -- cgit v1.2.3