1use crate::core::config;
5use crate::proxy::ProxyRunOptions;
6use anyhow::Result;
7use std::path::Path;
8use std::sync::Arc;
9
10pub fn cmd_proxy_run(
12 workspace: Option<&Path>,
13 listen: Option<String>,
14 upstream: Option<String>,
15 provider: Option<String>,
16) -> Result<()> {
17 let dir = workspace
18 .map(std::path::Path::to_path_buf)
19 .unwrap_or_else(|| std::env::current_dir().expect("cwd"));
20 let dir = std::fs::canonicalize(&dir).unwrap_or(dir);
21 let cfg = config::load(&dir)?;
22 let o = Arc::new(ProxyRunOptions::from_config_with_overrides(
23 &cfg, listen, upstream, provider,
24 ));
25 let rt = tokio::runtime::Builder::new_multi_thread()
26 .enable_all()
27 .build()?;
28 rt.block_on(async move { crate::proxy::run(o, dir, cfg).await })
29}