use std::time::SystemTime;
use crate::{logging::general::{log_execution_time, log_dry_run_note, log_repo_status}, cli::{Stage, VCSKind}, commands::stage::logging::log_staged_status};
use std::process::Command;
use colored::Colorize;
pub fn stage_command(stage_options: Stage, start_time: SystemTime) {
if stage_options.dry_run {
log_staged_status(stage_options.dry_run);
log_dry_run_note();
} else {
execute_stage();
}
log_execution_time(start_time);
}
fn execute_stage() {
match Command::new("git")
.arg("add")
.arg("-A")
.status() {
Ok(status) => {
if !status.success() {
panic!("Failed to stage files");
} else {
log_repo_status(false);
}
}
Err(error) => {
panic!("Failed to stage files: {}", error);
}
}
}
fn log_status(dry_run: bool, vcs: VCSKind) {
println!("{}\n", "VCS: ".yellow());
match vcs {
VCSKind::Git => {
print!("{}", "Git".green());
}
VCSKind::Mercurial => {
print!("{}", "Mercurial".red());
}
VCSKind::SVN => {
print!("{}", "SVN".blue());
}
VCSKind::Bazaar => {
print!("{}", "Bazaar".yellow());
}
VCSKind::CVS => {
print!("{}", "CVS".magenta());
}
}
}