vertigo_cli/
main.rs

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