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 && let Some(code) = crate::cli::enable_proxy(session, None).await {
11 return code;
12 }
13
14 let req = Request::Run {
15 command: command.into(),
16 name,
17 cwd: None,
18 env: None,
19 port,
20 };
21 crate::cli::request_and_handle(session, &req, true, |resp| match resp {
22 Response::RunOk {
23 name, id, pid, url, ..
24 } => {
25 match url {
26 Some(u) => println!("{} (id: {}, pid: {}, {})", name, id, pid, u),
27 None => println!("{} (id: {}, pid: {})", name, id, pid),
28 }
29 Some(0)
30 }
31 _ => None,
32 })
33 .await
34}