git-send 0.1.6

Commit and push changes with a single command
//! Configuration file handling

use std::fs;

/// Configuration file name
pub const CONFIG_FILE: &str = ".git-send.toml";

/// Configuration loaded from .git-send.toml
#[derive(Debug, Default)]
pub struct Config {
    pub default_message: Option<String>,
    pub auto_stash: Option<bool>,
    pub skip_hooks: Option<bool>,
    #[allow(dead_code)]
    pub test_commands: Vec<(String, Vec<String>)>,
}

impl Config {
    pub fn load() -> Self {
        Self::load_from_path(CONFIG_FILE)
    }

    pub fn load_from_path(path: &str) -> Self {
        let Ok(contents) = fs::read_to_string(path) else {
            return Self::default();
        };

        // Simple TOML parsing for basic key-value pairs
        let mut config = Self::default();

        for line in contents.lines() {
            let line = line.trim();
            if line.is_empty() || line.starts_with('#') {
                continue;
            }

            if let Some((key, value)) = line.split_once('=') {
                let key = key.trim();
                let value = value.trim().trim_matches('"').trim_matches('\'');

                match key {
                    "default_message" => config.default_message = Some(value.to_string()),
                    "auto_stash" => config.auto_stash = Some(value == "true"),
                    "skip_hooks" => config.skip_hooks = Some(value == "true"),
                    _ => {}
                }
            }
        }

        config
    }
}