rust-cmaker/src/main.rs
2023-04-17 16:49:49 +08:00

69 lines
1.7 KiB
Rust

pub mod build_project;
pub mod new_project;
pub const PROJECT_NAME: &str = "rust-cmaker";
use std::path::PathBuf;
use clap::{command, Parser};
/// 命令行参数
#[derive(Parser, Debug)]
#[command(author = "Cloyir mine123456@foxmail.com", version = "1.0.0", about = None, long_about = None)]
struct Args {
#[command(subcommand)]
command: Commands,
}
#[derive(Parser, Debug)]
enum Commands {
/// 在当前目录新建项目
#[command(about = "创建一个新项目")]
New {
/// 项目名称
#[clap(name = "new_project_name")]
project_name: String,
},
/// 在此项目内编译
#[command(about = "构建当前文件夹下的项目")]
Build {
/// -O优化选项
#[clap(short = 'o', long = "option", name = "0~3", default_value = "0")]
build_options: i32,
/// 编译后是否立即运行
#[clap(short, long, default_value = "false")]
run: bool,
/// MinGW编译器地址, 不填默认已配置为环境变量
#[clap(short, long, default_value = None)]
mingw: Option<String>,
},
}
fn main() -> std::io::Result<()> {
// 解析命令行参数
let args = Args::parse();
// println!("args: {:?}", args);
match args.command {
Commands::New { project_name } => {
new_project::new_project(project_name);
}
Commands::Build {
build_options,
run,
mingw,
} => {
let mingw = if let Some(t) = mingw {
Some(PathBuf::from(t))
} else {
None
};
build_project::build_project(build_options, run, mingw)?;
}
}
Ok(())
}