1#[cfg(all(test, feature = "full_tests"))]
2mod tests;
3
4mod command;
5pub mod compile;
6pub mod config;
7pub mod ext;
8mod logger;
9pub mod service;
10pub mod signal;
11
12use crate::config::Commands;
13use crate::ext::anyhow::{Context, Result};
14use crate::ext::PathBufExt;
15use crate::logger::GRAY;
16use camino::Utf8PathBuf;
17use config::{Cli, Config};
18use ext::fs;
19use signal::Interrupt;
20use std::env;
21
22pub async fn run(args: Cli) -> Result<()> {
23 let verbose = args.opts().map(|o| o.verbose).unwrap_or(0);
24 logger::setup(verbose, &args.log);
25
26 if let New(new) = &args.command {
27 return new.run().await;
28 }
29
30 let manifest_path = args
31 .manifest_path
32 .to_owned()
33 .unwrap_or_else(|| Utf8PathBuf::from("Cargo.toml"))
34 .resolve_home_dir()
35 .context(format!("manifest_path: {:?}", &args.manifest_path))?;
36 let mut cwd = Utf8PathBuf::from_path_buf(env::current_dir().unwrap()).unwrap();
37 cwd.clean_windows_path();
38
39 let opts = args.opts().unwrap();
40
41 let watch = matches!(args.command, Commands::Watch(_));
42 let config = Config::load(opts, &cwd, &manifest_path, watch).dot()?;
43 env::set_current_dir(&config.working_dir).dot()?;
44 log::debug!("Path working dir {}", GRAY.paint(config.working_dir.as_str()));
45
46 let _monitor = Interrupt::run_ctrl_c_monitor();
47 use Commands::{Build, EndToEnd, New, Serve, Test, Watch};
48 match args.command {
49 New(_) => panic!(),
50 Build(_) => command::build_all(&config).await,
51 Serve(_) => command::serve(&config.current_project()?).await,
52 Test(_) => command::test_all(&config).await,
53 EndToEnd(_) => command::end2end_all(&config).await,
54 Watch(_) => command::watch(&config.current_project()?).await,
55 }
56}