aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs26
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())