diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dab1b0..2482c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (defaulting to distant); this means that subsequent use of `distant client launch [user@]host[:port]` will now default to ssh instead of failing due to lack of distant launch handler +- Expose `windows-pipe` and `unix-socket` config and cli options regardless of + platform (so they can be provided without worrying about which OS) ## [0.17.1] - 2022-08-16 ### Added diff --git a/src/cli/commands/manager.rs b/src/cli/commands/manager.rs index f474f57..543ce5c 100644 --- a/src/cli/commands/manager.rs +++ b/src/cli/commands/manager.rs @@ -261,7 +261,9 @@ impl ManagerSubcommand { info!( "Starting manager (network = {})", - if network.as_opt().is_some() { + if (cfg!(windows) && network.windows_pipe.is_some()) + || (cfg!(unix) && network.unix_socket.is_some()) + { "custom" } else if user { "user" diff --git a/src/config/network.rs b/src/config/network.rs index 2dda804..48a37f6 100644 --- a/src/config/network.rs +++ b/src/config/network.rs @@ -41,13 +41,11 @@ pub struct NetworkConfig { #[clap(long, value_enum)] pub access: Option, - /// Override the path to the Unix socket used by the manager - #[cfg(unix)] + /// Override the path to the Unix socket used by the manager (unix-only) #[clap(long)] pub unix_socket: Option, - /// Override the name of the local named Windows pipe used by the manager - #[cfg(windows)] + /// Override the name of the local named Windows pipe used by the manager (windows-only) #[clap(long)] pub windows_pipe: Option, } @@ -56,30 +54,23 @@ impl NetworkConfig { pub fn merge(self, other: Self) -> Self { Self { access: self.access.or(other.access), - - #[cfg(unix)] unix_socket: self.unix_socket.or(other.unix_socket), - - #[cfg(windows)] windows_pipe: self.windows_pipe.or(other.windows_pipe), } } /// Returns option containing reference to unix path if configured - #[cfg(unix)] - pub fn as_opt(&self) -> Option<&std::path::Path> { + pub fn as_unix_socket_opt(&self) -> Option<&std::path::Path> { self.unix_socket.as_deref() } /// Returns option containing reference to windows pipe name if configured - #[cfg(windows)] - pub fn as_opt(&self) -> Option<&str> { + pub fn as_windows_pipe_opt(&self) -> Option<&str> { self.windows_pipe.as_deref() } /// Returns a collection of candidate unix socket paths, which will either be /// the config-provided unix socket path or the default user and global socket paths - #[cfg(unix)] pub fn to_unix_socket_path_candidates(&self) -> Vec<&std::path::Path> { match self.unix_socket.as_deref() { Some(path) => vec![path], @@ -92,7 +83,6 @@ impl NetworkConfig { /// Returns a collection of candidate windows pipe names, which will either be /// the config-provided windows pipe name or the default user and global pipe names - #[cfg(windows)] pub fn to_windows_pipe_name_candidates(&self) -> Vec<&str> { match self.windows_pipe.as_deref() { Some(name) => vec![name], diff --git a/src/paths.rs b/src/paths.rs index 7a4e0b5..c51a7e5 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -2,7 +2,6 @@ use directories::ProjectDirs; use once_cell::sync::Lazy; use std::path::PathBuf; -#[cfg(unix)] const SOCKET_FILE_STR: &str = "distant.sock"; /// User-oriented paths @@ -46,7 +45,6 @@ pub mod user { /// * `/run/user/1001/distant/{user}.distant.sock` on Linux /// * `/var/run/{user}.distant.sock` on BSD /// * `/tmp/{user}.distant.dock` on MacOS - #[cfg(unix)] pub static UNIX_SOCKET_PATH: Lazy = Lazy::new(|| { // Form of {user}.distant.sock let mut file_name = whoami::username_os(); @@ -61,7 +59,6 @@ pub mod user { }); /// Name of the pipe used by Windows in the form of `{user}.distant` - #[cfg(windows)] pub static WINDOWS_PIPE_NAME: Lazy = Lazy::new(|| format!("{}.distant", whoami::username())); } @@ -90,7 +87,6 @@ pub mod global { /// * `/run/distant.sock` on Linux /// * `/var/run/distant.sock` on BSD /// * `/tmp/distant.dock` on MacOS - #[cfg(unix)] pub static UNIX_SOCKET_PATH: Lazy = Lazy::new(|| { if cfg!(target_os = "macos") { std::env::temp_dir().join(SOCKET_FILE_STR) @@ -107,6 +103,5 @@ pub mod global { }); /// Name of the pipe used by Windows - #[cfg(windows)] pub static WINDOWS_PIPE_NAME: Lazy = Lazy::new(|| "distant".to_string()); }