1use crate::protocol::{Request, Response};
2
3pub async fn execute(
4 session: &str,
5 target: &str,
6 until: Option<String>,
7 regex: bool,
8 exit: bool,
9 timeout: Option<u64>,
10) -> i32 {
11 let req = Request::Wait {
12 target: target.into(),
13 until,
14 regex,
15 exit,
16 timeout_secs: timeout,
17 };
18 match crate::cli::request(session, &req, false).await {
19 Ok(Response::WaitMatch { line }) => {
20 println!("{}", line);
21 0
22 }
23 Ok(Response::WaitExited { exit_code }) => {
24 match exit_code {
25 Some(code) => println!("exited with code {}", code),
26 None => println!("exited by signal"),
27 }
28 0
29 }
30 Ok(Response::WaitTimeout) => {
31 eprintln!("timeout");
32 1
33 }
34 Ok(Response::Error { code, message }) => {
35 eprintln!("error: {}", message);
36 code
37 }
38 Ok(_) => {
39 eprintln!("unexpected response");
40 1
41 }
42 Err(e) => {
43 eprintln!("error: {}", e);
44 1
45 }
46 }
47}