From 675b90f2262c393850092fec788258cb74c079a2 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 23 Jan 2022 15:37:26 +0530 Subject: [PATCH] main: extract config path logic to its own method --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5512a7e..ce8ec21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod config; use std::error::Error; use std::ops::{Deref, Not}; +use std::path::PathBuf; use anyhow::{anyhow, Result}; use clipboard::{ClipboardContext, ClipboardProvider}; @@ -12,16 +13,21 @@ use crate::config::{Act, Match, Replacements}; fn main() -> Result<()> { pretty_env_logger::init(); - let mut config_path = config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?; - config_path.push("substitutor"); - config_path.push("config"); - config_path.set_extension("toml"); + let config_path = get_config_path()?; let config_str = std::fs::read_to_string(config_path.as_path()).unwrap_or_default(); let config: Replacements<'_> = toml::from_str(&config_str)?; loop_clipboard(config); return Ok(()); } +fn get_config_path() -> Result { + let mut config_path = config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?; + config_path.push("substitutor"); + config_path.push("config"); + config_path.set_extension("toml"); + return Ok(config_path); +} + fn loop_clipboard<'a>(config: Replacements<'a>) { let mut clipboard: ClipboardContext = ClipboardProvider::new().expect("Failed to get clipboard");