diff --git a/src/main.rs b/src/main.rs index 2e61759..5940532 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,28 @@ use crossterm::event::{self, Event}; use ratatui::{Frame, text::Text}; + +use crate::utils::clone_extension_template; mod utils; fn main() { // Check for git BEFORE initializing the terminal if !utils::is_git_installed() { eprintln!("Error: Git is not installed or not in PATH"); - eprintln!("Please install Git to use this application. For details see: https://git-scm.com/install/"); + eprintln!( + "Please install Git to use this application. For details see: https://git-scm.com/install/" + ); std::process::exit(1); } println!("✓ Git is installed and ready!"); - std::thread::sleep(std::time::Duration::from_secs(3)); + + if let Some(proj_name) = std::env::args().nth(1) { + println!("Project name: {}", &proj_name); + + clone_extension_template(proj_name).unwrap(); + + return; + } let mut terminal = ratatui::init(); loop { @@ -26,4 +37,4 @@ fn main() { fn draw(frame: &mut Frame) { let text = Text::raw("Hello, World!"); frame.render_widget(text, frame.area()); -} \ No newline at end of file +} diff --git a/src/utils.rs b/src/utils.rs index c7554a5..3332807 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,4 @@ +use std::io::{self}; use std::process::Command; pub fn is_git_installed() -> bool { @@ -6,4 +7,27 @@ pub fn is_git_installed() -> bool { .output() .map(|output| output.status.success()) .unwrap_or(false) -} \ No newline at end of file +} + +pub fn clone_extension_template(proj_name: String) -> Result<(), io::Error> { + let mut res = Command::new("git") + .args([ + "clone", + "--recurse-submodules", + "git@github.com:duckdb/extension-template.git", + &proj_name, + ]) + .spawn() + .expect("failed to clone project"); + res.wait().expect("project failed to clone"); + let mut path: String = proj_name.clone().to_owned(); + + path.push_str("/.git"); + + Command::new("rm") + .args(["-rf", &path]) + .spawn() + .expect("Could not delete .git directory"); + + Ok(()) +}