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 println!("exited with code {}", exit_code);
25 0
26 }
27 Ok(Response::WaitTimeout) => {
28 eprintln!("timeout");
29 1
30 }
31 Ok(Response::Error { code, message }) => {
32 eprintln!("error: {}", message);
33 code
34 }
35 Ok(_) => {
36 eprintln!("unexpected response");
37 1
38 }
39 Err(e) => {
40 eprintln!("error: {}", e);
41 1
42 }
43 }
44}