From dc5ded8160177864963a31476c2a7afe8ca8e834 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Wed, 19 Feb 2025 21:13:50 +0100 Subject: resource opener in config + implement config field `pdf_opener` for setting app to open PDFs/Epubs + implement config field `url_opener` for setting app to open URLs/DOIs + function to select fallback if no field is provided in config --- src/config.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index a80cc13..abb610b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,33 +17,51 @@ use std::path::PathBuf; +use color_eyre::eyre::Result; use config::{ConfigError, FileFormat}; use serde::Deserialize; use crate::cliargs::CLIArgs; +/// Main struct of the config file. Contains substructs/headings in toml #[derive(Debug, Clone, Deserialize)] pub struct BibiConfig { pub general: General, } +/// Substruct [general] in config.toml #[derive(Debug, Clone, Deserialize)] pub struct General { - pub bibfiles: Vec, + pub bibfiles: Option>, pub editor: Option, + pub pdf_opener: Option, + pub url_opener: Option, } impl BibiConfig { - pub fn default(args: &CLIArgs) -> Self { + pub fn default() -> Self { Self { general: General { - bibfiles: args.pos_args.clone(), + bibfiles: None, editor: None, + pdf_opener: None, + url_opener: None, }, } } - pub fn new(args: &CLIArgs) -> Result { + pub fn new(args: &CLIArgs) -> Result { + // let mut cfg = config::Config::builder(); + // cfg = cfg.add_source( + // config::File::from(args.cfg_path.clone()) + // .format(FileFormat::Toml) + // .required(false), + // ); + // cfg.build()?.try_deserialize() + Ok(Self::parse_cfg_file(args)?) + } + + fn parse_cfg_file(args: &CLIArgs) -> Result { let mut cfg = config::Config::builder(); cfg = cfg.add_source( config::File::from(args.cfg_path.clone()) -- cgit v1.2.3