use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ServerAccess<'a> {
#[cfg(feature = "tmux_3_3")]
pub add: bool,
#[cfg(feature = "tmux_3_3")]
pub delete: bool,
#[cfg(feature = "tmux_3_3")]
pub list: bool,
#[cfg(feature = "tmux_3_3")]
pub read: bool,
#[cfg(feature = "tmux_3_3")]
pub write: bool,
#[cfg(feature = "tmux_3_3")]
pub user: Option<Cow<'a, str>>,
}
impl<'a> ServerAccess<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_3_3")]
pub fn add(mut self) -> Self {
self.add = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn delete(mut self) -> Self {
self.delete = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn list(mut self) -> Self {
self.list = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn read(mut self) -> Self {
self.read = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn write(mut self) -> Self {
self.write = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn user<S: Into<Cow<'a, str>>>(mut self, user: S) -> Self {
self.user = Some(user.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SERVER_ACCESS);
#[cfg(feature = "tmux_3_3")]
if self.add {
cmd.push_flag(A_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.delete {
cmd.push_flag(D_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.list {
cmd.push_flag(L_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.read {
cmd.push_flag(R_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.write {
cmd.push_flag(W_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if let Some(user) = self.user {
cmd.push_param(user);
}
cmd
}
}