kitty_remote_bindings/command/
launch.rs

1use crate::Result;
2use kitty_remote_bindings_macros::KittyCommand;
3use std::process::Output;
4
5use super::{
6    options::{Cwd, LaunchType, Matcher},
7    CommandOutput,
8};
9
10/// Represents the "launch" remote command: kitty @ launch
11#[derive(Debug, PartialEq, KittyCommand)]
12#[kitty_command = "launch"]
13pub struct Launch {
14    #[top_level]
15    /// Sets the `--to` top level option
16    to: Option<String>,
17    #[option = "match"]
18    /// Sets the `--match` option
19    matcher: Option<Matcher>,
20    #[option = "type"]
21    /// Sets the `--type` option
22    launch_type: Option<LaunchType>,
23    /// Sets the `cwd` option
24    cwd: Option<Cwd>,
25    /// Sets the positional arguments of the launch command
26    args: Vec<String>,
27}
28
29impl CommandOutput for Launch {
30    type R = ();
31
32    fn result(output: &Output) -> Result<Self::R> {
33        if output.status.success() {
34            Ok(())
35        } else {
36            Err(crate::Error::ErrorExit("kitty @ focus-window".to_string()))
37        }
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use std::path::PathBuf;
44
45    use pretty_assertions::assert_eq;
46
47    use crate::command::options::{Cwd, LaunchType};
48
49    use super::Launch;
50
51    #[test]
52    fn test_launch_command() {
53        let cmd = Launch::new(vec!["program".to_string(), "arg1".to_string()])
54            .launch_type(LaunchType::OsWindow)
55            .cwd(Cwd::Path(PathBuf::from("/home/user")));
56
57        let std_cmd = std::process::Command::from(&cmd);
58
59        assert_eq!(
60            std_cmd.get_args().collect::<Vec<_>>(),
61            vec![
62                "@",
63                "launch",
64                "--type",
65                "os-window",
66                "--cwd",
67                "/home/user",
68                "program",
69                "arg1"
70            ]
71        );
72    }
73}