Skip to main content

solar_core/subcommand/
new.rs

1use std::{fs, path::PathBuf};
2
3use clap::Parser;
4
5use crate::{Init, SolarError};
6
7#[derive(Parser, Clone)]
8pub struct New {
9    /// The name of the new projecct.
10    name: String,
11
12    /// The destination to create the new project.
13    #[arg(short, long, default_value = ".")]
14    destination: PathBuf,
15}
16
17impl New {
18    pub fn run(&self) -> Result<(), SolarError> {
19        // Ensure the destination directory exists
20        let project_dir = self.destination.join(&self.name);
21        fs::create_dir_all(&project_dir)?;
22
23        // Initialize the project
24        let initializer: Init = Init::parse_from(vec![
25            "",
26            project_dir
27                .to_str()
28                .ok_or("Failed to convert destination path to string.")?,
29        ]);
30        initializer.run()?;
31
32        Ok(())
33    }
34}