Skip to main content

agent_procs/cli/
wait.rs

1use crate::protocol::{Request, Response};
2
3pub async fn execute(
4    session: &str, target: &str, until: Option<String>,
5    regex: bool, exit: bool, timeout: Option<u64>,
6) -> i32 {
7    let req = Request::Wait {
8        target: target.into(), until, regex, exit,
9        timeout_secs: timeout,
10    };
11    match crate::cli::request(session, &req, false).await {
12        Ok(Response::WaitMatch { line }) => { println!("{}", line); 0 }
13        Ok(Response::WaitExited { exit_code }) => { println!("exited with code {}", exit_code); 0 }
14        Ok(Response::WaitTimeout) => { eprintln!("timeout"); 1 }
15        Ok(Response::Error { code, message }) => { eprintln!("error: {}", message); code }
16        Ok(_) => { eprintln!("unexpected response"); 1 }
17        Err(e) => { eprintln!("error: {}", e); 1 }
18    }
19}