-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use colored::*; | ||
use std::process::Command; | ||
|
||
pub fn check_git() -> Result<(), String> { | ||
if Command::new("git").arg("--version").spawn().is_err() { | ||
return Err("Git is not installed. Please install git and try again.".to_string()); | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn git_init(project_root: &str) { | ||
if let Err(e) = check_git() { | ||
println!("{}: {}", "error".red().bold(), e.red().bold()); | ||
return; | ||
} | ||
|
||
if let Err(e) = std::env::set_current_dir(project_root) { | ||
println!( | ||
"{}: {}", | ||
"error".red().bold(), | ||
format!("Failed to change directory: {}", e).red().bold() | ||
); | ||
return; | ||
} | ||
|
||
let cmd = Command::new("git") | ||
.arg("init") //TODO: maybe add git arguments? that can be a bit risky.. | ||
.stderr(std::process::Stdio::null()) // hide hints and errors | ||
.status(); | ||
|
||
if let Ok(status) = cmd { | ||
if status.success() { | ||
println!("{}", "\n✅ Git initialized successfully.".green().bold()); | ||
} else { | ||
println!( | ||
"{}: {}", | ||
"error".red().bold(), | ||
"Git initialization failed.".red().bold() | ||
); | ||
} | ||
} else { | ||
println!( | ||
"{}: {}", | ||
"error".red().bold(), | ||
"Failed to run git command.".red().bold() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use serde::{Deserialize, Serialize}; | ||
pub mod git; | ||
pub mod opts; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Options { | ||
pub git: bool, | ||
pub json_data: Option<serde_json::Value>, | ||
pub project_root: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::options::git; | ||
use crate::Options; | ||
use colored::*; | ||
|
||
impl Default for Options { | ||
fn default() -> Self { | ||
Self { | ||
json_data: Some(serde_json::Value::Null), | ||
git: false, | ||
project_root: String::new(), | ||
} | ||
} | ||
} | ||
|
||
impl Options { | ||
pub fn set_git(&mut self, git: bool) { | ||
self.git = git; | ||
} | ||
|
||
pub fn set_json(&mut self, json_data: serde_json::Value) { | ||
self.json_data = Some(json_data); | ||
} | ||
|
||
pub fn set_project_root(&mut self, project_root: &str) { | ||
self.project_root = project_root.to_string(); | ||
} | ||
|
||
pub fn handle_options(self) { | ||
if self.git { | ||
if self.project_root.is_empty() { | ||
println!( | ||
"{}: {}", | ||
"error".red().bold(), | ||
"Please specify a project root.".red().bold() | ||
); | ||
return; | ||
} | ||
|
||
println!( | ||
"\nInitializing git repository for {}\n", | ||
self.project_root.blue() | ||
); | ||
|
||
git::git_init(&self.project_root); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters