use std::path::PathBuf;
use crate::config::{default_config, Config, Destination, Path};
#[derive(clap::Args)]
#[command(about = "Create a new Bular project")]
pub struct Command {
#[arg(
help = "The name of the project. Thiis folder will be created in the current directory."
)]
name: String,
}
impl Command {
pub async fn run(&self, cwd: PathBuf) {
let dir = cwd.join(self.name.clone());
if dir.exists() {
eprintln!("The directory already exists: {dir:?}");
std::process::exit(1);
}
let bular_id = None;
std::process::Command::new("cargo")
.arg("new")
.arg(&self.name)
.arg("--bin")
.current_dir(&cwd)
.status()
.unwrap();
std::fs::write(
dir.join("bular.yaml"),
serde_yaml::to_string(&default_config(self.name.clone(), bular_id)).unwrap(),
)
.unwrap();
println!("Done!");
}
}