tmux_interface/commands/clients_and_sessions/
kill_session_macro.rs

1/// Destroy the given session
2///
3/// # Manual
4///
5/// tmux ^2.2:
6/// ```text
7/// kill-session [-aC] [-t target-session]
8/// ```
9///
10/// tmux ^1.7:
11/// ```text
12/// kill-session [-a] [-t target-session]
13/// ```
14///
15/// tmux ^0.8:
16/// ```text
17/// kill-session [-t target-session]
18/// ```
19#[macro_export]
20macro_rules! kill_session {
21    (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
22        $crate::kill_session!(@cmd ({
23            $cmd.all()
24        }) $($tail)*)
25    }};
26    (@cmd ($cmd:expr) -C, $($tail:tt)*) => {{
27        $crate::kill_session!(@cmd ({
28            $cmd.clear_alerts()
29        }) $($tail)*)
30    }};
31    // `[-s target-session]` - specify the session, all clients currently attached
32    (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
33        $crate::kill_session!(@cmd ({
34            $cmd.target_session($target_session)
35        }) $($tail)*)
36    }};
37    //(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
38        //::std::compile_error!("unknown flag, option or parameter");
39    //}};
40    (@cmd ($cmd:expr)) => {{
41        $cmd
42    }};
43    () => {{
44        $crate::KillSession::new()
45    }};
46    (($cmd:expr), $($tail:tt)*) => {{
47        $crate::kill_session!(@cmd ($cmd) $($tail)*,)
48    }};
49    ($($tail:tt)*) => {{
50        $crate::kill_session!(@cmd ({ $crate::KillSession::new() }) $($tail)*,)
51    }};
52
53}
54
55#[test]
56fn kill_session_macro() {
57    use crate::TargetSession;
58    use std::borrow::Cow;
59
60    // Destroy the given session
61    //
62    // # Manual
63    //
64    // tmux ^2.2:
65    // ```text
66    // kill-session [-aC] [-t target-session]
67    // ```
68    //
69    // tmux ^1.7:
70    // ```text
71    // kill-session [-a] [-t target-session]
72    // ```
73    //
74    // tmux ^0.8:
75    // ```text
76    // kill-session [-t target-session]
77    // ```
78    let target_session = TargetSession::Raw("1").to_string();
79
80    let kill_session = kill_session!();
81    #[cfg(feature = "tmux_2_2")]
82    let kill_session = kill_session!((kill_session), -a);
83    #[cfg(feature = "tmux_1_7")]
84    let kill_session = kill_session!((kill_session), -C);
85    #[cfg(feature = "tmux_0_8")]
86    let kill_session = kill_session!((kill_session), -t & target_session);
87
88    let cmd = "kill-session";
89
90    let mut s = Vec::new();
91    s.push(cmd);
92    #[cfg(feature = "tmux_2_2")]
93    s.push("-a");
94    #[cfg(feature = "tmux_1_7")]
95    s.push("-C");
96    #[cfg(feature = "tmux_0_8")]
97    s.extend_from_slice(&["-t", "1"]);
98    let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
99
100    let kill_session = kill_session.build().to_vec();
101
102    assert_eq!(kill_session, s);
103}