diff --git a/shared/src/interface_config.rs b/shared/src/interface_config.rs index a01be4e..2e0ada0 100644 --- a/shared/src/interface_config.rs +++ b/shared/src/interface_config.rs @@ -1,8 +1,16 @@ -use crate::{CLIENT_CONFIG_DIR, Endpoint, Error, IoErrorContext, WrappedIoError, ensure_dirs_exist}; +use crate::{ + ensure_dirs_exist, Endpoint, Error, IoErrorContext, WrappedIoError, CLIENT_CONFIG_DIR, +}; use indoc::writedoc; use ipnetwork::IpNetwork; use serde::{Deserialize, Serialize}; -use std::{fs::{File, OpenOptions}, io::{self, Write}, net::SocketAddr, os::unix::fs::PermissionsExt, path::{Path, PathBuf}}; +use std::{ + fs::{File, OpenOptions}, + io::{self, Write}, + net::SocketAddr, + os::unix::fs::PermissionsExt, + path::{Path, PathBuf}, +}; use wgctrl::InterfaceName; #[derive(Clone, Deserialize, Serialize, Debug)] @@ -75,8 +83,7 @@ impl InterfaceConfig { " )?; } - target_file - .write_all(toml::to_string(self).unwrap().as_bytes())?; + target_file.write_all(toml::to_string(self).unwrap().as_bytes())?; Ok(()) } @@ -92,7 +99,8 @@ impl InterfaceConfig { .write(true) .open(path) .with_path(path)?; - self.write_to(&mut target_file, comments, mode).with_path(path) + self.write_to(&mut target_file, comments, mode) + .with_path(path) } /// Overwrites the config file if it already exists. diff --git a/shared/src/prompts.rs b/shared/src/prompts.rs index 3f92f63..306c491 100644 --- a/shared/src/prompts.rs +++ b/shared/src/prompts.rs @@ -9,7 +9,14 @@ use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select}; use ipnetwork::IpNetwork; use lazy_static::lazy_static; use publicip::Preference; -use std::{fmt::{Debug, Display}, fs::{File, OpenOptions}, io, net::SocketAddr, str::FromStr, time::SystemTime}; +use std::{ + fmt::{Debug, Display}, + fs::{File, OpenOptions}, + io, + net::SocketAddr, + str::FromStr, + time::SystemTime, +}; use wgctrl::{InterfaceName, KeyPair}; lazy_static! { @@ -20,7 +27,10 @@ pub fn ensure_interactive(prompt: &str) -> Result<(), io::Error> { if atty::is(atty::Stream::Stdin) { Ok(()) } else { - Err(io::Error::new(io::ErrorKind::BrokenPipe, format!("Prompt \"{}\" failed because TTY isn't connected.", prompt))) + Err(io::Error::new( + io::ErrorKind::BrokenPipe, + format!("Prompt \"{}\" failed because TTY isn't connected.", prompt), + )) } } @@ -45,7 +55,7 @@ pub fn select<'a, T: ToString>(prompt: &str, items: &'a [T]) -> Result<(usize, & pub enum Prefill { Default(T), Editable(String), - None + None, } pub fn input(prompt: &str, prefill: Prefill) -> Result @@ -58,8 +68,10 @@ where match prefill { Prefill::Default(value) => input.default(value), Prefill::Editable(value) => input.with_initial_text(value), - _ => &mut input - }.with_prompt(prompt).interact() + _ => &mut input, + } + .with_prompt(prompt) + .interact() } /// Bring up a prompt to create a new CIDR. Returns the peer request. @@ -246,13 +258,19 @@ pub fn add_peer( let invite_expires = if let Some(ref invite_expires) = args.invite_expires { invite_expires.clone() } else { - input("Invite expires after", Prefill::Default("14d".parse().map_err(|s: &str| anyhow!(s))?))? + input( + "Invite expires after", + Prefill::Default("14d".parse().map_err(|s: &str| anyhow!(s))?), + )? }; let invite_save_path = if let Some(ref location) = args.save_config { location.clone() } else { - input("Save peer invitation file to", Prefill::Default(format!("{}.toml", name)))? + input( + "Save peer invitation file to", + Prefill::Default(format!("{}.toml", name)), + )? }; let default_keypair = KeyPair::generate(); @@ -412,7 +430,10 @@ pub fn set_listen_port( ) -> Result>, Error> { let listen_port = (!unset) .then(|| { - input("Listen port", Prefill::Default(interface.listen_port.unwrap_or(51820))) + input( + "Listen port", + Prefill::Default(interface.listen_port.unwrap_or(51820)), + ) }) .transpose()?; @@ -451,10 +472,13 @@ pub fn ask_endpoint() -> Result { None }; - Ok(input("External endpoint", match external_ip { - Some(ip) => Prefill::Editable(SocketAddr::new(ip, 51820).to_string()), - None => Prefill::None - })?) + Ok(input( + "External endpoint", + match external_ip { + Some(ip) => Prefill::Editable(SocketAddr::new(ip, 51820).to_string()), + None => Prefill::None, + }, + )?) } pub fn override_endpoint(unset: bool) -> Result>, Error> {