bular 0.0.2

CLI for managing Bular deployments
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);
        }

        // TODO: Prompt the user to setup with Bular and create a project
        let bular_id = None;

        // TODO: Maybe using `create-rspc-app` v2 for this instead?
        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();

        // TODO: Pretty UI
        println!("Done!");
    }
}