diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 23:33:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 23:33:27 +0300 |
| commit | 043b804c44665b07bd503fdad896bbe0a29311a0 (patch) | |
| tree | 79bae0b64ba1c0e22328b0401196587633399c60 /src/cli.rs | |
| parent | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (diff) | |
feat: route cli commands to saved ssh machines (#3918)
Diffstat (limited to 'src/cli.rs')
| -rw-r--r-- | src/cli.rs | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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<std::io::Result<CommandOutcome>> { + target::maybe_run(args) +} + pub fn maybe_run(args: &[String]) -> std::io::Result<CommandOutcome> { 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<i32> { } pub(super) fn send_request(request: &Request) -> std::io::Result<serde_json::Value> { - 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<serde_json::Val } pub(super) fn send_request_unchecked(request: &Request) -> std::io::Result<serde_json::Value> { - 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( |
