1use clap::{Parser, Subcommand};
2use env_logger::Builder;
3use log::LevelFilter;
4use std::process::exit;
5
6pub mod build;
7mod commons;
8pub mod new;
9pub mod serve;
10pub mod watch;
11
12pub use build::BuildOpts;
13pub use commons::models::CommonOpts;
14pub use new::NewOpts;
15pub use serve::ServeOpts;
16pub use watch::WatchOpts;
17
18#[derive(Parser)]
19#[command(author, version, about, long_about = None)]
20#[command(propagate_version = true)]
21struct Cli {
22 #[command(subcommand)]
23 command: Command,
24}
25
26#[derive(Subcommand)]
27enum Command {
28 New(NewOpts),
29 Build(BuildOpts),
30 Serve(ServeOpts),
31 Watch(WatchOpts),
32}
33
34#[tokio::main]
35pub async fn main() -> Result<(), i32> {
36 Builder::new()
37 .filter_level(LevelFilter::Info)
38 .parse_env("RUST_LOG")
39 .filter(Some("cranelift_codegen"), LevelFilter::Warn)
40 .filter(Some("wasmtime_cranelift::compiler"), LevelFilter::Warn)
41 .init();
42
43 let cli = Cli::parse();
44
45 let ret = match cli.command {
46 Command::Build(opts) => build::run(opts),
47 Command::New(opts) => new::run(opts),
48 Command::Serve(opts) => serve::run(opts, None).await,
49 Command::Watch(opts) => watch::run(opts).await,
50 };
51
52 if let Err(err) = ret {
54 exit(err as i32);
55 }
56
57 Ok(())
58}