Skip to content

Commit

Permalink
Add logging logic to config module
Browse files Browse the repository at this point in the history
  • Loading branch information
szaffarano committed Feb 2, 2025
1 parent a172a6e commit 7f49558
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use anyhow::Context;
use log::debug;
use std::{fs, path::PathBuf};

use directories_next::{self, BaseDirs};
use serde::{Deserialize, Serialize};

/// CLI configuration
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
#[serde(default)]
Expand Down Expand Up @@ -42,12 +44,17 @@ pub struct ModeConfig {
pub description: String,
}

/// Load configuration from a file
pub fn load(path: &PathBuf) -> anyhow::Result<Config> {
debug!("Loading config from file: {:?}", path);

let config = fs::read_to_string(path).context("Error reading config file")?;
toml::from_str(&config).context("Error parsing config file")
}

/// Load the default configuration
pub fn load_default() -> anyhow::Result<Config> {
debug!("Loading config from the default location");
let dirs = BaseDirs::new().expect("Error getting base directories");

let config_path = dirs.config_dir().join("rofi-cliphist.toml");
Expand All @@ -57,6 +64,7 @@ pub fn load_default() -> anyhow::Result<Config> {

impl Default for Config {
fn default() -> Self {
debug!("Creating default config");
Self {
rofi: Rofi::default(),
cliphist: ClipHist::default(),
Expand Down

0 comments on commit 7f49558

Please sign in to comment.