Skip to main content

agent_procs/cli/
run.rs

1use crate::protocol::{Request, Response};
2
3pub async fn execute(
4    session: &str,
5    command: &str,
6    name: Option<String>,
7    port: Option<u16>,
8    proxy: bool,
9) -> i32 {
10    if proxy {
11        if let Some(code) = crate::cli::enable_proxy(session, None).await {
12            return code;
13        }
14    }
15
16    let req = Request::Run {
17        command: command.into(),
18        name,
19        cwd: None,
20        env: None,
21        port,
22    };
23    match crate::cli::request(session, &req, true).await {
24        Ok(Response::RunOk {
25            name, id, pid, url, ..
26        }) => {
27            match url {
28                Some(u) => println!("{} (id: {}, pid: {}, {})", name, id, pid, u),
29                None => println!("{} (id: {}, pid: {})", name, id, pid),
30            }
31            0
32        }
33        Ok(Response::Error { code, message }) => {
34            eprintln!("error: {}", message);
35            code
36        }
37        Ok(_) => {
38            eprintln!("unexpected response");
39            1
40        }
41        Err(e) => {
42            eprintln!("error: {}", e);
43            1
44        }
45    }
46}