Skip to main content

tnnl/
config.rs

1use serde::Deserialize;
2use std::path::PathBuf;
3
4#[derive(Debug, Default, Deserialize)]
5pub struct Config {
6    pub server: Option<String>,
7    pub token: Option<String>,
8    pub control_port: Option<u16>,
9    pub subdomain: Option<String>,
10    pub inspect: Option<bool>,
11    pub auth: Option<String>,
12}
13
14pub fn load() -> Config {
15    let path = config_path();
16    let Ok(contents) = std::fs::read_to_string(&path) else {
17        return Config::default();
18    };
19    toml::from_str(&contents).unwrap_or_default()
20}
21
22fn config_path() -> PathBuf {
23    std::env::var_os("HOME")
24        .map(PathBuf::from)
25        .unwrap_or_else(|| PathBuf::from("."))
26        .join(".tnnl.toml")
27}