use serde::{Deserialize, Serialize};
use crate::engine::rules::SingleWindowClose;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct Config {
pub offer_agents: bool,
pub offer_shells: bool,
pub ask_on_start: bool,
pub single_window_close: SingleWindowClose,
pub codex_no_daemon: bool,
}
impl Default for Config {
fn default() -> Self {
Config {
offer_agents: true,
offer_shells: true,
ask_on_start: true,
single_window_close: SingleWindowClose::Forget,
codex_no_daemon: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn missing_options_have_their_defaults() {
let config: Config = toml::from_str("offer-shells = false").unwrap();
assert_eq!(
config,
Config {
offer_shells: false,
..Config::default()
}
);
}
#[test]
fn options_survive_a_round_trip_through_toml() {
let config = Config {
ask_on_start: false,
single_window_close: SingleWindowClose::Offer,
codex_no_daemon: true,
..Config::default()
};
let text = toml::to_string(&config).unwrap();
assert!(text.contains("single-window-close = \"offer\""));
assert!(text.contains("codex-no-daemon = true"));
assert_eq!(toml::from_str::<Config>(&text).unwrap(), config);
}
}