mirror of
https://github.com/SeriousBug/gandi-live-dns-rust
synced 2024-05-19 03:39:04 -05:00
32 lines
798 B
Rust
32 lines
798 B
Rust
|
use directories::ProjectDirs;
|
||
|
use serde::Deserialize;
|
||
|
use std::error::Error;
|
||
|
use std::fs;
|
||
|
use std::path::PathBuf;
|
||
|
use crate::opts;
|
||
|
|
||
|
#[derive(Deserialize, Debug)]
|
||
|
pub struct Config {
|
||
|
fqdn: String,
|
||
|
}
|
||
|
|
||
|
pub fn load_config(file: PathBuf) -> Result<Config, Box<dyn Error>> {
|
||
|
let output = fs::read_to_string(file)?;
|
||
|
let contents = output.as_str();
|
||
|
|
||
|
let config = toml::from_str(contents)?;
|
||
|
return Ok(config);
|
||
|
}
|
||
|
|
||
|
pub fn config_path(opts: &opts::Opts) -> PathBuf {
|
||
|
return opts
|
||
|
.config
|
||
|
.as_ref()
|
||
|
.and_then(|conf| Some(PathBuf::from(conf)))
|
||
|
.unwrap_or(
|
||
|
ProjectDirs::from("me", "kaangenc", "gandi-dynamic-dns")
|
||
|
.and_then(|dir| Some(PathBuf::from(dir.config_dir())))
|
||
|
.unwrap_or(PathBuf::from(".")),
|
||
|
);
|
||
|
}
|