diff --git a/src/bin/dosh-client.rs b/src/bin/dosh-client.rs index d1373b3..81348b8 100644 --- a/src/bin/dosh-client.rs +++ b/src/bin/dosh-client.rs @@ -2727,17 +2727,23 @@ fn launch_vscode_remote(alias: &str, remote_path: Option<&str>) -> Result<()> { } if saw_not_found { println!( - "Run: code --remote {}{}", - shell_word(&remote), - remote_path - .map(|path| format!(" {}", shell_word(path))) - .unwrap_or_default() + "Run: {}", + vscode_fallback_command(std::env::consts::OS, &remote, remote_path) ); return Ok(()); } Err(anyhow!("no VS Code command candidates configured")) } +fn vscode_fallback_command(os: &str, remote: &str, remote_path: Option<&str>) -> String { + let mut command = format!("code --remote {}", ssh_config_word_for_os(os, remote)); + if let Some(path) = remote_path { + command.push(' '); + command.push_str(&ssh_config_word_for_os(os, path)); + } + command +} + fn vscode_command_candidates(os: &str) -> &'static [&'static str] { if os == "windows" { &["code.cmd", "code.exe", "code"] @@ -10633,11 +10639,12 @@ mod tests { summarize_trace_file_with_mode, terminal_private_mode_transition, toml_bare_key_or_quoted, top_trace_events, trace_report_warnings, unix_update_script, update_binary_version_for_installer, update_installer_url, update_version_status, - upsert_managed_block, valid_forward_host, vscode_command_candidates, vscode_safe_alias, - wake_repaint_retry_deadline, windows_command_word, windows_deferred_update_script, - windows_effective_url_script, windows_mode_from_readonly, - windows_powershell_command_candidates, windows_readonly_from_mode, windows_update_script, - windows_url_reachable_script, windows_vt_output_mode, + upsert_managed_block, valid_forward_host, vscode_command_candidates, + vscode_fallback_command, vscode_safe_alias, wake_repaint_retry_deadline, + windows_command_word, windows_deferred_update_script, windows_effective_url_script, + windows_mode_from_readonly, windows_powershell_command_candidates, + windows_readonly_from_mode, windows_update_script, windows_url_reachable_script, + windows_vt_output_mode, }; use dosh::config::{ClientConfig, CommandExtension, HostConfig}; use dosh::native::EnvVar; @@ -10700,6 +10707,22 @@ mod tests { ); } + #[test] + fn vscode_fallback_command_quotes_for_each_platform() { + assert_eq!( + vscode_fallback_command("macos", "ssh-remote+dosh-prod", Some("/srv/my app")), + "code --remote 'ssh-remote+dosh-prod' '/srv/my app'" + ); + assert_eq!( + vscode_fallback_command( + "windows", + "ssh-remote+dosh-prod", + Some(r#"C:\Users\alice\My App"#) + ), + r#"code --remote "ssh-remote+dosh-prod" "C:\Users\alice\My App""# + ); + } + #[test] fn forward_agent_endpoint_disabled_is_none() { assert_eq!(resolve_forward_agent_endpoint(false).unwrap(), None);