vertigo_cli/
main.rs

1use clap::{Parser, Subcommand};
2use std::process::exit;
3
4pub mod build;
5mod commons;
6pub mod new;
7pub mod serve;
8pub mod watch;
9
10pub use build::BuildOpts;
11pub use commons::models::CommonOpts;
12pub use new::NewOpts;
13pub use serve::ServeOpts;
14pub use watch::WatchOpts;
15
16use commons::logging::setup_logging;
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    let cli = Cli::parse();
37
38    setup_logging(&cli.command);
39
40    let ret = match cli.command {
41        Command::Build(opts) => build::run(opts),
42        Command::New(opts) => new::run(opts),
43        Command::Serve(opts) => serve::run(opts, None).await,
44        Command::Watch(opts) => watch::run(opts).await,
45    };
46
47    // Tokio doesn't proparate error codes to shell, so do it manually
48    if let Err(err) = ret {
49        exit(err as i32);
50    }
51
52    Ok(())
53}