feat: use XDG_CONFIG_HOME
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
a96ddb2879
commit
ee0b8f79d9
1 changed files with 12 additions and 2 deletions
14
src/main.rs
14
src/main.rs
|
@ -2,6 +2,7 @@ use std::{error::Error, path::PathBuf};
|
||||||
|
|
||||||
mod config {
|
mod config {
|
||||||
use std::{
|
use std::{
|
||||||
|
env,
|
||||||
error::Error,
|
error::Error,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -35,7 +36,16 @@ mod config {
|
||||||
/// Loads the configuration toml from a path into the Config struct.
|
/// Loads the configuration toml from a path into the Config struct.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(path: PathBuf) -> Result<Self, Box<dyn Error>> {
|
pub fn new(path: PathBuf) -> Result<Self, Box<dyn Error>> {
|
||||||
let yaml = fs::read_to_string(path)?;
|
let yaml = match fs::read_to_string(path) {
|
||||||
|
Ok(content) => content,
|
||||||
|
_ => match fs::read_to_string(format!(
|
||||||
|
"{}/hilsen/config.yaml",
|
||||||
|
env::var("XDG_CONFIG_HOME").unwrap()
|
||||||
|
)) {
|
||||||
|
Ok(content) => content,
|
||||||
|
_ => panic!(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let config = serde_yaml::from_str(&yaml)?;
|
let config = serde_yaml::from_str(&yaml)?;
|
||||||
|
|
||||||
|
@ -128,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
if let Some(config_file) = matches.get_one::<PathBuf>("config") {
|
if let Some(config_file) = matches.get_one::<PathBuf>("config") {
|
||||||
config = config::Config::new(config_file.clone())?;
|
config = config::Config::new(config_file.clone())?;
|
||||||
} else {
|
} else {
|
||||||
panic!();
|
config = config::Config::new("".into())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.get_flag("showConfigParse") {
|
if matches.get_flag("showConfigParse") {
|
||||||
|
|
Loading…
Reference in a new issue