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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
/// Structure for creating a new session
///
/// # Manual
///
/// tmux 3.3:
/// ```text
/// server-access [-adlrw] [user]
/// ```
///
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ServerAccess<'a> {
/// `[-a]` - give access
#[cfg(feature = "tmux_3_3")]
pub add: bool,
/// `[-d]` - revoke access
#[cfg(feature = "tmux_3_3")]
pub delete: bool,
/// `[-l]` - list current access permissions
#[cfg(feature = "tmux_3_3")]
pub list: bool,
/// `[-r]` - read-only permission for user
#[cfg(feature = "tmux_3_3")]
pub read: bool,
/// `[-w]` - write permission for user
#[cfg(feature = "tmux_3_3")]
pub write: bool,
/// `\[user\]` - user
#[cfg(feature = "tmux_3_3")]
pub user: Option<Cow<'a, str>>,
}
impl<'a> ServerAccess<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-a]` - give access
#[cfg(feature = "tmux_3_3")]
pub fn add(mut self) -> Self {
self.add = true;
self
}
/// `[-d]` - revoke access
#[cfg(feature = "tmux_3_3")]
pub fn delete(mut self) -> Self {
self.delete = true;
self
}
/// `[-l]` - list current access permissions
#[cfg(feature = "tmux_3_3")]
pub fn list(mut self) -> Self {
self.list = true;
self
}
/// `[-r]` - read-only permission for user
#[cfg(feature = "tmux_3_3")]
pub fn read(mut self) -> Self {
self.read = true;
self
}
/// `[-w]` - write permission for user
#[cfg(feature = "tmux_3_3")]
pub fn write(mut self) -> Self {
self.write = true;
self
}
/// `\[user\]` - user
#[cfg(feature = "tmux_1_9")]
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);
// `[-a]` - give access
#[cfg(feature = "tmux_3_3")]
if self.add {
cmd.push_flag(A_LOWERCASE_KEY);
}
// `[-d]` - revoke access
#[cfg(feature = "tmux_3_3")]
if self.delete {
cmd.push_flag(D_LOWERCASE_KEY);
}
// `[-l]` - list current access permissions
#[cfg(feature = "tmux_3_3")]
if self.list {
cmd.push_flag(L_LOWERCASE_KEY);
}
// `[-r]` - read-only permission for user
#[cfg(feature = "tmux_3_3")]
if self.read {
cmd.push_flag(R_LOWERCASE_KEY);
}
// `[-w]` - write permission for user
#[cfg(feature = "tmux_3_3")]
if self.write {
cmd.push_flag(W_LOWERCASE_KEY);
}
// `\[user\]` - user
#[cfg(feature = "tmux_3_3")]
if let Some(user) = self.user {
cmd.push_param(user);
}
cmd
}
}