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    crate::cli::request_and_handle(session, &req, true, |resp| match resp {
24        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            Some(0)
32        }
33        _ => None,
34    })
35    .await
36}