diff options
| author | lukeflo | 2025-02-19 21:13:50 +0100 |
|---|---|---|
| committer | lukeflo | 2025-02-19 21:13:50 +0100 |
| commit | dc5ded8160177864963a31476c2a7afe8ca8e834 (patch) | |
| tree | abc0e3293b89fa24d3b9a7cbfe5dbc9d83d1d8b5 /src/config.rs | |
| parent | 3bdd57994d94839aef04871bd0247f2b82b71d35 (diff) | |
| download | bibiman-dc5ded8160177864963a31476c2a7afe8ca8e834.tar.gz bibiman-dc5ded8160177864963a31476c2a7afe8ca8e834.zip | |
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
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 26 |
1 files changed, 22 insertions, 4 deletions
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<PathBuf>, + pub bibfiles: Option<Vec<PathBuf>>, pub editor: Option<String>, + pub pdf_opener: Option<String>, + pub url_opener: Option<String>, } 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<Self, ConfigError> { + pub fn new(args: &CLIArgs) -> Result<Self> { + // 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<Self, ConfigError> { let mut cfg = config::Config::builder(); cfg = cfg.add_source( config::File::from(args.cfg_path.clone()) |
