create_lamdera_app_rs/
github.rs1use crate::error::Result;
2use colored::*;
3use std::process::Command;
4
5pub fn create_repository(project_name: &str, is_public: bool) -> Result<String> {
6 let visibility = if is_public { "public" } else { "private" };
7
8 println!(
9 "{}",
10 format!("Creating {} GitHub repository...", visibility).yellow()
11 );
12
13 let output = Command::new("gh")
14 .args([
15 "repo",
16 "create",
17 project_name,
18 &format!("--{}", visibility),
19 "--source=.",
20 "--remote=origin",
21 ])
22 .output()?;
23
24 if !output.status.success() {
25 let error = String::from_utf8_lossy(&output.stderr);
26 return Err(anyhow::anyhow!("Failed to create GitHub repository: {}", error));
27 }
28
29 println!("{}", "✓ Created GitHub repository".green());
30
31 let url = String::from_utf8_lossy(&output.stdout);
33 Ok(url.trim().to_string())
34}
35
36pub fn is_gh_cli_installed() -> bool {
37 Command::new("gh")
38 .arg("--version")
39 .output()
40 .map(|output| output.status.success())
41 .unwrap_or(false)
42}
43
44pub fn is_gh_cli_authenticated() -> bool {
45 Command::new("gh")
46 .args(["auth", "status"])
47 .output()
48 .map(|output| output.status.success())
49 .unwrap_or(false)
50}