1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::tmux_interface::*;
use super::tmux_interface_error::TmuxInterfaceError;
use std::process::Output;
#[derive(Default)]
pub struct SetEnvironment<'a> {
pub global: Option<bool>,
pub remove: Option<bool>,
pub unset: Option<bool>,
pub target_session: Option<&'a str>,
pub name: &'a str,
pub value: Option<&'a str>
}
impl<'a> SetEnvironment<'a> {
pub fn new() -> Self {
Default::default()
}
}
impl<'a> TmuxInterface<'a> {
const SET_ENVIRONMENT: &'static str = "set-environment";
const SHOW_ENVIRONMENT: &'static str = "show-environment";
pub fn set_environment(&self,
set_environment: &SetEnvironment
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if set_environment.global.unwrap_or(false) { args.push(g_KEY); }
if set_environment.remove.unwrap_or(false) { args.push(r_KEY); }
if set_environment.unset.unwrap_or(false) { args.push(u_KEY); }
set_environment.target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(set_environment.name);
set_environment.value.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::SET_ENVIRONMENT, &args)?;
Ok(output)
}
pub fn show_environment(&self,
global: Option<bool>,
shell_format: Option<bool>,
target_session: Option<&str>,
variable: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if global.unwrap_or(false) { args.push(g_KEY); }
if shell_format.unwrap_or(false) { args.push(s_KEY); }
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
variable.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::SHOW_ENVIRONMENT, &args)?;
Ok(output)
}
}