stellar_scaffold_cli/commands/
init.rs1use clap::Parser;
2use degit::degit;
3use std::fs::{metadata, read_dir};
4use std::io;
5
6const FRONTEND_TEMPLATE: &str = "https://github.com/AhaLabs/scaffold-stellar-frontend";
7
8#[derive(Parser, Debug, Clone)]
10pub struct Cmd {
11 pub project_path: String,
13}
14
15#[derive(thiserror::Error, Debug)]
17pub enum Error {
18 #[error("Failed to clone template: {0}")]
19 DegitError(String),
20 #[error("IO error: {0}")]
21 IoError(#[from] io::Error),
22}
23
24impl Cmd {
25 #[allow(clippy::unused_self)]
34 pub fn run(&self) -> Result<(), Error> {
35 eprintln!("ℹ️ Creating new Stellar project in {}", self.project_path);
36 degit(FRONTEND_TEMPLATE, &self.project_path);
37
38 if metadata(&self.project_path).is_err() || read_dir(&self.project_path)?.next().is_none() {
40 return Err(Error::DegitError(format!(
41 "Failed to clone template into {}: directory is empty or missing",
42 self.project_path
43 )));
44 }
45
46 eprintln!("✅ Project successfully created at {}", self.project_path);
47 Ok(())
48 }
49}