Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -26,4 +37,4 @@ fn main() {
fn draw(frame: &mut Frame) {
let text = Text::raw("Hello, World!");
frame.render_widget(text, frame.area());
}
}
26 changes: 25 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::{self};
use std::process::Command;

pub fn is_git_installed() -> bool {
Expand All @@ -6,4 +7,27 @@ pub fn is_git_installed() -> bool {
.output()
.map(|output| output.status.success())
.unwrap_or(false)
}
}

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(())
}