Rust library to generate static websites
at fix/misc-errors 81 lines 2.1 kB view raw
1mod build; 2mod dev; 3mod init; 4mod preview; 5 6mod consts; 7 8mod logging; 9mod server_utils; 10 11use clap::{Parser, Subcommand}; 12use dev::start_dev_env; 13use logging::init_logging; 14use preview::start_preview_web_server; 15use std::path::{Path, PathBuf}; 16 17#[derive(Parser)] 18#[command(author, version, about, long_about = None)] 19#[command(propagate_version = true)] 20struct Cli { 21 #[command(subcommand)] 22 command: Commands, 23} 24 25#[derive(Subcommand)] 26enum Commands { 27 /// Initialize a new Maudit project 28 Init { 29 #[clap(long, short)] 30 dry_run: bool, 31 }, 32 /// Build the project 33 Build, 34 /// Run the project in development mode 35 Dev { 36 #[clap(long)] 37 host: bool, 38 39 /// Port to run the dev server on 40 #[clap(long, short, default_value_t = crate::consts::PORT)] 41 port: u16, 42 }, 43 /// Preview the project 44 Preview { 45 #[clap(long)] 46 host: bool, 47 }, 48} 49 50#[tokio::main] 51async fn main() { 52 init_logging(); 53 let cli = Cli::parse(); 54 55 // You can check for the existence of subcommands, and if found use their 56 // matches just as you would the top level cmd 57 match &cli.command { 58 Commands::Init { dry_run } => { 59 init::start_new_project(dry_run); 60 } 61 Commands::Build => { 62 build::start_build(); 63 } 64 Commands::Preview { host } => { 65 // TODO: Dist path is hardcoded for now. Ideally, Maudit should output some kind of metadata file that can be read by the CLI. 66 let dist_path = Path::new("dist"); 67 if !dist_path.exists() { 68 println!( 69 "The dist directory does not exist. Please run `maudit build` or `cargo build` first." 70 ); 71 return; 72 } 73 74 let _ = start_preview_web_server(PathBuf::from("dist"), *host).await; 75 } 76 Commands::Dev { host, port } => { 77 // TODO: cwd should be configurable, ex: --root <path> 78 let _ = start_dev_env(".", *host, Some(*port)).await; 79 } 80 } 81}