Skip to content

Commit

Permalink
fix: use error! and home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 committed Jul 9, 2024
1 parent af8739b commit fa12d8e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ mockall = "0.12.1"
keystore = { git = "https://github.com/deltadevsde/keystore", rev = "40f21a41afd0654091bb0881665288034ab8533f" }
pyroscope = "0.5.7"
pyroscope_pprofrs = "0.2.7"
toml = "0.8.14"
toml = "0.8.14"
dirs = "5.0.1"
10 changes: 6 additions & 4 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{Parser, Subcommand};
use config::{builder::DefaultState, ConfigBuilder, File};
use dirs::home_dir;
use serde::{Deserialize, Serialize};
use std::{fs, path::Path, sync::Arc};

Expand Down Expand Up @@ -134,9 +135,10 @@ impl Default for Config {
}

pub fn load_config(args: CommandLineArgs) -> Result<Config, config::ConfigError> {
let config_path = args
.config_path
.unwrap_or_else(|| ".deimos/config.toml".to_string());
let config_path = args.config_path.unwrap_or_else(|| {
let home_dir = home_dir().expect("Failed to get home directory");
format!("{}/.deimos/config.toml", home_dir.to_string_lossy())
});

// if the config file doesn't exist, create it with the default values
if !Path::new(&config_path).exists() {
Expand All @@ -155,7 +157,7 @@ pub fn load_config(args: CommandLineArgs) -> Result<Config, config::ConfigError>

let default_config = Config::default();
let file_config: Config = settings.try_deserialize().unwrap_or_else(|e| {
debug!("Failed to deserialize config file: {}", e);
error!("deserializing config file: {}", e);
Config::default()
});

Expand Down

0 comments on commit fa12d8e

Please sign in to comment.