diff --git a/src/iwd.rs b/src/iwd.rs index c410017..659d144 100644 --- a/src/iwd.rs +++ b/src/iwd.rs @@ -104,19 +104,25 @@ fn attempt_connection( ssid: &str, passphrase: Option, ) -> Result> { - let command = match passphrase { - Some(ref pwd) => format!("--passphrase '{pwd}' station {interface} connect '{ssid}'"), - None => format!("station {interface} connect '{ssid}'"), - }; + let mut command_args = vec![ + "station".to_string(), + interface.to_string(), + "connect".to_string(), + ssid.to_string(), + ]; + if let Some(pwd) = passphrase { + command_args.push("--passphrase".to_string()); + command_args.push(pwd); + } - let status = Command::new("iwctl").args(command.split(' ')).status()?; + let status = Command::new("iwctl").args(&command_args).status()?; if status.success() { notify_connection(ssid)?; Ok(true) } else { #[cfg(debug_assertions)] - eprintln!("Failed to connect to Wi-Fi network: {ssid}"); + eprintln!("Failed to connect to Wi-Fi network: {}", ssid); Ok(false) } }