Skip to main content

agent_procs/cli/
run.rs

1use crate::protocol::{Request, Response, RestartPolicy, WatchConfig};
2
3#[allow(clippy::too_many_arguments)]
4pub async fn execute(
5    session: &str,
6    command: &str,
7    name: Option<String>,
8    port: Option<u16>,
9    proxy: bool,
10    autorestart: Option<String>,
11    max_restarts: Option<u32>,
12    restart_delay: Option<u64>,
13    watch: Vec<String>,
14    watch_ignore: Vec<String>,
15) -> i32 {
16    if proxy && let Some(code) = crate::cli::enable_proxy(session, None).await {
17        return code;
18    }
19
20    let restart = autorestart.map(|m| RestartPolicy::from_args(&m, max_restarts, restart_delay));
21    let watch_config = WatchConfig::from_args(watch, watch_ignore);
22
23    let req = Request::Run {
24        command: command.into(),
25        name,
26        cwd: None,
27        env: None,
28        port,
29        restart,
30        watch: watch_config,
31    };
32    crate::cli::request_and_handle(session, &req, true, |resp| match resp {
33        Response::RunOk {
34            name, id, pid, url, ..
35        } => {
36            match url {
37                Some(u) => println!("{} (id: {}, pid: {}, {})", name, id, pid, u),
38                None => println!("{} (id: {}, pid: {})", name, id, pid),
39            }
40            Some(0)
41        }
42        _ => None,
43    })
44    .await
45}