wasm_startup/
lib.rs

1#![allow(unused)]
2use clap::{Args, Parser, Subcommand};
3use tracing::{error, trace};
4mod build;
5mod log;
6mod new;
7mod utils;
8
9/// 快速启动wasm
10#[derive(Debug, Parser)]
11#[command(author,version,long_about = None)]
12struct StartUp {
13    /// Debug mode
14    #[arg(short, long, action=clap::ArgAction::Count)]
15    debug: u8,
16
17    #[command(subcommand)]
18    commands: Commands,
19}
20
21#[derive(Debug, Subcommand)]
22pub(crate) enum Commands {
23    /// 新建项目
24    New(NewArgs),
25    /// 打包项目
26    Build,
27}
28#[derive(Debug, Args)]
29struct NewArgs {
30    #[arg(short, long,action=clap::ArgAction::Count)]
31    /// 使用vite typescript 搭建实时测试环境
32    vite: u8,
33    /// vite项目名称
34    #[arg(short, long)]
35    name: Option<String>,
36}
37
38impl Commands {
39    fn run(&self) {
40        match &self {
41            Commands::New(NewArgs { vite, name }) => Commands::new(*vite, name),
42            Commands::Build => Commands::build(),
43        }
44    }
45}
46
47impl StartUp {
48    fn start_up(&self) {
49        trace!("{:?}", self);
50        self.commands.run();
51    }
52}
53
54pub fn init() {
55    let cli = StartUp::parse();
56    log::log(cli.debug == 1);
57    match utils::check() {
58        Ok(_) => cli.start_up(),
59        Err(e) => {
60            error!("{}", e);
61            std::process::exit(1);
62        }
63    }
64}