mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 20:07:01 +05:30
main: extract config path logic to its own method
This commit is contained in:
parent
2d4776d7d0
commit
675b90f226
1 changed files with 10 additions and 4 deletions
14
src/main.rs
14
src/main.rs
|
@ -2,6 +2,7 @@ mod config;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ops::{Deref, Not};
|
use std::ops::{Deref, Not};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||||
|
@ -12,16 +13,21 @@ use crate::config::{Act, Match, Replacements};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
let mut config_path = config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?;
|
let config_path = get_config_path()?;
|
||||||
config_path.push("substitutor");
|
|
||||||
config_path.push("config");
|
|
||||||
config_path.set_extension("toml");
|
|
||||||
let config_str = std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
let config_str = std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
||||||
let config: Replacements<'_> = toml::from_str(&config_str)?;
|
let config: Replacements<'_> = toml::from_str(&config_str)?;
|
||||||
loop_clipboard(config);
|
loop_clipboard(config);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_config_path() -> Result<PathBuf> {
|
||||||
|
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>) {
|
fn loop_clipboard<'a>(config: Replacements<'a>) {
|
||||||
let mut clipboard: ClipboardContext =
|
let mut clipboard: ClipboardContext =
|
||||||
ClipboardProvider::new().expect("Failed to get clipboard");
|
ClipboardProvider::new().expect("Failed to get clipboard");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue