oseda_cli/
github.rs

1/*
2user.email=hatfield.69@wright.edu
3user.name=ReeseHatfield
4core.editor=/usr/bin/vim
5*/
6
7use std::{error::Error, path::Path, process::Command};
8
9pub fn get_config(key: &str) -> Option<String> {
10    let handle = Command::new("git")
11        .arg("config")
12        .arg("list")
13        .output()
14        .ok()?;
15
16    let conf_out = String::from_utf8(handle.stdout).ok()?;
17
18    conf_out.split("\n").find_map(|line| {
19        // restrict to only the first 2, shouldnt matter but good convention
20
21        let (cur_key, value) = line.split_once('=')?;
22        if cur_key == key {
23            Some(value.to_string())
24        } else {
25            None
26        }
27    })
28}
29
30// super generic run git func for general usecases
31pub fn git(dir: &Path, args: &[&str]) -> Result<(), Box<dyn Error>> {
32    let status = Command::new("git").current_dir(dir).args(args).status()?;
33
34    if !status.success() {
35        return Err(format!("git {:?} failed", args).into());
36    }
37    Ok(())
38}