diff --git a/client/src/main.rs b/client/src/main.rs index 6845ade..22cbfa2 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -10,9 +10,9 @@ use shared::{ prompts, wg::{DeviceExt, PeerInfoExt}, AddCidrOpts, AddDeleteAssociationOpts, AddPeerOpts, Association, AssociationContents, Cidr, - CidrTree, DeleteCidrOpts, Endpoint, EndpointContents, InstallOpts, Interface, IoErrorContext, - ListenPortOpts, NatOpts, NetworkOpts, OverrideEndpointOpts, Peer, RedeemContents, - RenamePeerOpts, EnableDisablePeerOpts, State, WrappedIoError, REDEEM_TRANSITION_WAIT, + CidrTree, DeleteCidrOpts, EnableDisablePeerOpts, Endpoint, EndpointContents, InstallOpts, + Interface, IoErrorContext, ListenPortOpts, NatOpts, NetworkOpts, OverrideEndpointOpts, Peer, + RedeemContents, RenamePeerOpts, State, WrappedIoError, REDEEM_TRANSITION_WAIT, }; use std::{ fmt, io, @@ -212,7 +212,7 @@ enum Command { }, /// Disable an enabled peer - DisablePeer { + DisablePeer { interface: Interface, #[clap(flatten)] @@ -220,7 +220,7 @@ enum Command { }, /// Enable a disabled peer - EnablePeer { + EnablePeer { interface: Interface, #[clap(flatten)] @@ -1262,11 +1262,11 @@ fn run(opts: &Opts) -> Result<(), Error> { sub_opts, } => delete_cidr(&interface, opts, sub_opts)?, Command::ListCidrs { interface, tree } => list_cidrs(&interface, opts, tree)?, - Command::DisablePeer { + Command::DisablePeer { interface, sub_opts, } => enable_or_disable_peer(&interface, opts, sub_opts, false)?, - Command::EnablePeer { + Command::EnablePeer { interface, sub_opts, } => enable_or_disable_peer(&interface, opts, sub_opts, true)?, diff --git a/server/src/main.rs b/server/src/main.rs index f8bd499..e11e68d 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -9,8 +9,8 @@ use parking_lot::{Mutex, RwLock}; use rusqlite::Connection; use serde::{Deserialize, Serialize}; use shared::{ - get_local_addrs, AddCidrOpts, AddPeerOpts, DeleteCidrOpts, Endpoint, IoErrorContext, - NetworkOpts, PeerContents, RenamePeerOpts, EnableDisablePeerOpts, INNERNET_PUBKEY_HEADER, + get_local_addrs, AddCidrOpts, AddPeerOpts, DeleteCidrOpts, EnableDisablePeerOpts, Endpoint, + IoErrorContext, NetworkOpts, PeerContents, RenamePeerOpts, INNERNET_PUBKEY_HEADER, }; use std::{ collections::{HashMap, VecDeque}, @@ -96,20 +96,20 @@ enum Command { }, /// Disable an enabled peer - DisablePeer { + DisablePeer { interface: Interface, - + #[clap(flatten)] args: EnableDisablePeerOpts, }, /// Enable a disabled peer - EnablePeer { + EnablePeer { interface: Interface, #[clap(flatten)] args: EnableDisablePeerOpts, - }, + }, /// Rename an existing peer. RenamePeer { diff --git a/shared/src/prompts.rs b/shared/src/prompts.rs index d613c0b..bc84b8f 100644 --- a/shared/src/prompts.rs +++ b/shared/src/prompts.rs @@ -1,8 +1,8 @@ use crate::{ interface_config::{InterfaceConfig, InterfaceInfo, ServerInfo}, AddCidrOpts, AddDeleteAssociationOpts, AddPeerOpts, Association, Cidr, CidrContents, CidrTree, - DeleteCidrOpts, Endpoint, Error, Hostname, IpNetExt, ListenPortOpts, OverrideEndpointOpts, - Peer, PeerContents, RenamePeerOpts, EnableDisablePeerOpts, PERSISTENT_KEEPALIVE_INTERVAL_SECS, + DeleteCidrOpts, EnableDisablePeerOpts, Endpoint, Error, Hostname, IpNetExt, ListenPortOpts, + OverrideEndpointOpts, Peer, PeerContents, RenamePeerOpts, PERSISTENT_KEEPALIVE_INTERVAL_SECS, }; use anyhow::anyhow; use colored::*; @@ -396,7 +396,11 @@ pub fn rename_peer( /// Presents a selection and confirmation of eligible peers for either disabling or enabling, /// and returns back the ID of the selected peer. -pub fn enable_or_disable_peer(peers: &[Peer], args: &EnableDisablePeerOpts, enable: bool) -> Result, Error> { +pub fn enable_or_disable_peer( + peers: &[Peer], + args: &EnableDisablePeerOpts, + enable: bool, +) -> Result, Error> { let enabled_peers: Vec<_> = peers .iter() .filter(|peer| enable && peer.is_disabled || !enable && !peer.is_disabled) @@ -426,7 +430,7 @@ pub fn enable_or_disable_peer(peers: &[Peer], args: &EnableDisablePeerOpts, enab "{}able peer {}?", if enable { "En" } else { "Dis" }, peer.name.yellow() - ))? + ))? { Some(peer.clone()) } else { diff --git a/shared/src/types.rs b/shared/src/types.rs index a326b49..6b2099f 100644 --- a/shared/src/types.rs +++ b/shared/src/types.rs @@ -348,7 +348,6 @@ pub struct RenamePeerOpts { pub yes: bool, } - #[derive(Debug, Clone, PartialEq, Eq, Args)] pub struct EnableDisablePeerOpts { /// Name of peer to enable/disable