killswitch/cli/actions/
mod.rs1pub mod run;
2
3use crate::cli::verbosity::Verbosity;
4use anyhow::Result;
5
6#[derive(Debug)]
7pub enum Action {
8 Enable {
9 ipv4: Option<String>,
10 leak: bool,
11 local: bool,
12 verbose: Verbosity,
13 },
14 Disable {
15 verbose: Verbosity,
16 },
17 Status {
18 verbose: Verbosity,
19 },
20 Print {
21 ipv4: Option<String>,
22 leak: bool,
23 local: bool,
24 verbose: Verbosity,
25 },
26 ShowInterfaces {
27 verbose: Verbosity,
28 },
29}
30
31impl Action {
32 pub fn execute(&self) -> Result<()> {
37 run::execute(self)
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44 use crate::cli::verbosity::Verbosity;
45
46 #[test]
47 fn test_action_debug_format() {
48 let action = Action::Enable {
49 ipv4: Some("10.8.0.1".to_string()),
50 leak: false,
51 local: false,
52 verbose: Verbosity::Normal,
53 };
54 let debug_str = format!("{action:?}");
55 assert!(debug_str.contains("Enable"));
56 assert!(debug_str.contains("10.8.0.1"));
57 }
58
59 #[test]
60 fn test_action_variants() {
61 let enable = Action::Enable {
62 ipv4: None,
63 leak: true,
64 local: true,
65 verbose: Verbosity::Verbose,
66 };
67 assert!(matches!(enable, Action::Enable { .. }));
68
69 let disable = Action::Disable {
70 verbose: Verbosity::Normal,
71 };
72 assert!(matches!(disable, Action::Disable { .. }));
73
74 let status = Action::Status {
75 verbose: Verbosity::Debug,
76 };
77 assert!(matches!(status, Action::Status { .. }));
78
79 let print = Action::Print {
80 ipv4: Some("192.168.1.1".to_string()),
81 leak: false,
82 local: false,
83 verbose: Verbosity::Normal,
84 };
85 assert!(matches!(print, Action::Print { .. }));
86 }
87}