tmux_interface/commands/global_and_session_environment/
show_environment_macro.rs

1/// # Manual
2///
3/// tmux ^3.2:
4/// ```text:
5/// show-environment [-hgs] [-t target-session] [variable]
6/// (alias: showenv)
7/// ```
8///
9/// tmux ^2.1:
10/// ```text
11/// show-environment [-gs] [-t target-session] [variable]
12/// (alias: showenv)
13/// ```
14///
15/// tmux ^1.7:
16/// ```text
17/// show-environment [-g] [-t target-session] [variable]
18/// (alias: showenv)
19/// ```
20///
21/// tmux ^1.0:
22/// ```text
23/// show-environment [-g] [-t target-session]
24/// (alias: showenv)
25/// ```
26#[macro_export]
27macro_rules! show_environment {
28    // `[-h]`
29    (@cmd ($cmd:expr) -h, $($tail:tt)*) => {{
30        $crate::show_environment!(@cmd ({
31            $cmd.hidden()
32        }) $($tail)*)
33    }};
34    // `[-g]`
35    (@cmd ($cmd:expr) -g, $($tail:tt)*) => {{
36        $crate::show_environment!(@cmd ({
37            $cmd.global()
38        }) $($tail)*)
39    }};
40    // `[-s]`
41    (@cmd ($cmd:expr) -s, $($tail:tt)*) => {{
42        $crate::show_environment!(@cmd ({
43            $cmd.as_shell_commands()
44        }) $($tail)*)
45    }};
46    // `[-t target-session]` - target-session
47    (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
48        $crate::show_environment!(@cmd ({
49            $cmd.target_session($target_session)
50        }) $($tail)*)
51    }};
52    // `[variable]`
53    (@cmd ($cmd:expr) $variable:expr, $($tail:tt)*) => {{
54        $crate::show_environment!(@cmd ({
55            $cmd.variable($variable)
56        }) $($tail)*)
57    }};
58    //(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
59        //::std::compile_error!("unknown flag, option or parameter");
60    //}};
61    (@cmd ($cmd:expr)) => {{
62        $cmd
63    }};
64    () => {{
65        $crate::ShowEnvironment::new()
66    }};
67    (($cmd:expr), $($tail:tt)*) => {{
68        $crate::show_environment!(@cmd ($cmd) $($tail)*,)
69    }};
70    ($($tail:tt)*) => {{
71        $crate::show_environment!(@cmd ({ $crate::ShowEnvironment::new() }) $($tail)*,)
72    }};
73
74}
75
76#[test]
77fn show_environment() {
78    use crate::TargetSession;
79    use std::borrow::Cow;
80
81    // # Manual
82    //
83    // tmux ^3.2:
84    // ```text:
85    // show-environment [-hgs] [-t target-session] [variable]
86    // (alias: showenv)
87    // ```
88    //
89    // tmux ^2.1:
90    // ```text
91    // show-environment [-gs] [-t target-session] [variable]
92    // (alias: showenv)
93    // ```
94    //
95    // tmux ^1.7:
96    // ```text
97    // show-environment [-g] [-t target-session] [variable]
98    // (alias: showenv)
99    // ```
100    //
101    // tmux ^1.0:
102    // ```text
103    // show-environment [-g] [-t target-session]
104    // (alias: showenv)
105    // ```
106    let target_session = TargetSession::Raw("1").to_string();
107
108    let show_environment = show_environment!();
109    #[cfg(feature = "tmux_3_2")]
110    let show_environment = show_environment!((show_environment), -h);
111    #[cfg(feature = "tmux_1_0")]
112    let show_environment = show_environment!((show_environment), -g);
113    #[cfg(feature = "tmux_2_1")]
114    let show_environment = show_environment!((show_environment), -s);
115    #[cfg(feature = "tmux_1_7")]
116    let show_environment = show_environment!((show_environment), -t & target_session);
117    #[cfg(feature = "tmux_1_7")]
118    let show_environment = show_environment!((show_environment), "2");
119
120    #[cfg(not(feature = "cmd_alias"))]
121    let cmd = "show-environment";
122    #[cfg(feature = "cmd_alias")]
123    let cmd = "showenv";
124
125    let mut s = Vec::new();
126    s.push(cmd);
127    #[cfg(feature = "tmux_3_2")]
128    s.push("-h");
129    #[cfg(feature = "tmux_1_0")]
130    s.push("-g");
131    #[cfg(feature = "tmux_2_1")]
132    s.push("-s");
133    #[cfg(feature = "tmux_1_7")]
134    s.extend_from_slice(&["-t", "1"]);
135    #[cfg(feature = "tmux_1_7")]
136    s.push("2");
137    let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
138
139    let show_environment = show_environment.build().to_vec();
140
141    assert_eq!(show_environment, s);
142}