| 68 | } |
| 69 | |
| 70 | fn main() -> Result<()> { |
| 71 | let cli = Cli::parse(); |
| 72 | ui::init(cli.no_color); |
| 73 | ctrlc::set_handler(|| std::process::exit(130)).ok(); |
| 74 | |
| 75 | let manifest_path = cli.packages.unwrap_or_else(|| PathBuf::from("packages.json")); |
| 76 | |
| 77 | let result = match cli.cmd { |
| 78 | Cmd::Init { name, bare } => init::run(name.as_deref(), bare), |
| 79 | Cmd::Add { pkgs } => pkg::add(&manifest_path, &pkgs), |
| 80 | Cmd::Remove { pkgs } => pkg::remove(&manifest_path, &pkgs), |
| 81 | Cmd::Serve { port, open } => serve::run(PathBuf::from("."), port, open), |
| 82 | Cmd::Run { file } => run_script(&manifest_path, file.as_deref()), |
| 83 | Cmd::Repl => repl::run(&manifest_path), |
| 84 | Cmd::Build { out } => build::run(&manifest_path, out.unwrap_or_else(|| PathBuf::from("dist"))), |
| 85 | Cmd::Uninstall => uninstall::run(), |
| 86 | // Last one standing: needs a `test` module + discovery + reporter on top of the engine. |
| 87 | Cmd::Test { .. } => bail!("not wired yet: edge test"), |
| 88 | }; |
| 89 | |
| 90 | if let Err(e) = result { |
| 91 | ui::error(&e); |
| 92 | std::process::exit(1); |
| 93 | } |
| 94 | Ok(()) |
| 95 | } |
| 96 | |
| 97 | /// Read a script from `file` (or stdin when absent) and run it; a script that raises exits non-zero. |
| 98 | fn run_script(manifest_path: &Path, file: Option<&Path>) -> Result<()> { |