use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type SetEnv<'a> = SetEnvironment<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SetEnvironment<'a> {
#[cfg(feature = "tmux_3_2")]
pub expand: bool,
#[cfg(feature = "tmux_3_2")]
pub hidden: bool,
#[cfg(feature = "tmux_1_5")]
pub global: bool,
#[cfg(feature = "tmux_1_5")]
pub remove: bool,
#[cfg(feature = "tmux_1_5")]
pub unset: bool,
#[cfg(feature = "tmux_1_5")]
pub target_session: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub name: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub value: Option<Cow<'a, str>>,
}
impl<'a> SetEnvironment<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_3_2")]
pub fn expand(mut self) -> Self {
self.expand = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn hidden(mut self) -> Self {
self.hidden = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn global(mut self) -> Self {
self.global = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn remove(mut self) -> Self {
self.remove = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn unset(mut self) -> Self {
self.unset = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
self.target_session = Some(target_session.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn name<S: Into<Cow<'a, str>>>(mut self, name: S) -> Self {
self.name = Some(name.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn value<S: Into<Cow<'a, str>>>(mut self, value: S) -> Self {
self.value = Some(value.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SET_ENVIRONMENT);
#[cfg(feature = "tmux_3_2")]
if self.expand {
cmd.push_flag(F_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.hidden {
cmd.push_flag(H_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.global {
cmd.push_flag(G_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.remove {
cmd.push_flag(R_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.unset {
cmd.push_flag(U_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if let Some(target_session) = self.target_session {
cmd.push_option(T_LOWERCASE_KEY, target_session);
}
#[cfg(feature = "tmux_1_5")]
if let Some(name) = self.name {
cmd.push_param(name);
}
#[cfg(feature = "tmux_1_5")]
if let Some(value) = self.value {
cmd.push_param(value);
}
cmd
}
}