1use figment::{
2 providers::{Format, Serialized, Toml},
3 Figment,
4};
5use serde::{Deserialize, Serialize};
6use std::{env, path::Path};
7
8#[derive(Debug, Serialize, Deserialize)]
9pub struct GlobalConfig {
10 pub ninja: String,
12
13 pub keep_build_dir: bool,
15
16 pub verbose: bool,
18}
19
20impl Default for GlobalConfig {
21 fn default() -> Self {
22 Self {
23 ninja: "ninja".to_string(),
24 keep_build_dir: false,
25 verbose: false,
26 }
27 }
28}
29
30pub(crate) fn config_path(name: &str) -> std::path::PathBuf {
32 let config_base = env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| {
34 let home = env::var("HOME").expect("$HOME not set");
35 home + "/.config"
36 });
37 let config_path = Path::new(&config_base).join(name).with_extension("toml");
38 log::info!("Loading config from {}", config_path.display());
39 config_path
40}
41
42pub(crate) fn load_config(name: &str) -> Figment {
44 let config_path = config_path(name);
45
46 Figment::from(Serialized::defaults(GlobalConfig::default()))
48 .merge(Toml::file(config_path))
49}