use std::{env, fs};
use crate::core::{self, is_empty_dir};
pub fn run(name: Option<String>, axum: bool, apps: Vec<String>) {
let cur_dir = env::current_dir().unwrap().canonicalize().unwrap();
let (root, name) = match name {
Some(v) => {
let root = cur_dir.join(&v);
if !is_empty_dir(&root) {
println!("👿 The directory({:?}) is not empty, please confirm!", root);
return;
}
fs::create_dir_all(root.clone()).unwrap();
(root, v)
}
None => {
if cur_dir.join("Cargo.toml").exists() {
println!("👿 The current directory already exists Cargo.toml, please confirm!");
return;
}
let v = cur_dir.file_name().unwrap().to_string_lossy().to_string();
(cur_dir, v)
}
};
if axum {
core::build_axum_project(&root, name, apps);
} else {
core::build_salvo_project(&root, name, apps);
}
println!("🦀 Project creation completed! please read README")
}