scud 0.2.0

A secret library atm, woo woo.
use std::time::SystemTime;

use crate::{logging::general::{log_execution_time, log_dry_run_note, log_repo_status}, cli::Unstage, commands::unstage::logging::log_unstaged_status};
use std::process::Command;

pub fn unstage_command(unstage_options: Unstage, start_time: SystemTime) {
    if unstage_options.dry_run {
        log_repo_status(unstage_options.dry_run);
        log_dry_run_note();
    } else {
        execute_unstage();
    }

    log_execution_time(start_time);
}

fn execute_unstage() {
    let latest_commit_hash_raw = Command::new("git")
        .arg("log")
        .arg("-1")
        .arg("--format=%H")
        .output()
        .expect("Failed to get most recent commit from log").stdout;

    let latest_commit_hash = String::from_utf8_lossy(&latest_commit_hash_raw).to_string();

    match Command::new("git")
        .arg("reset")
        .arg(latest_commit_hash.as_str().trim())
        .status() {
        Ok(status) => {
            if !status.success() {
                panic!("Failed to unstage files");
            } else {
                log_unstaged_status(false);
            }
        }
        Err(error) => {
            panic!("Failed to unstage files: {}", error);
        }
    }
}