diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs index 3acfd90..e40c35f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,7 @@ const APP: &str = "jt2"; struct InputConfiguration { dirname: Option<PathBuf>, editor: Option<String>, + entries: Option<PathBuf>, } impl InputConfiguration { @@ -43,6 +44,11 @@ pub struct Configuration { /// The editor to open for editing journal entry drafts. pub editor: String, + + /// The directory where new entries are put. + /// + /// This is the full path name, not relative to `dirname`. + pub entries: PathBuf, } impl Configuration { @@ -74,14 +80,16 @@ impl Configuration { InputConfiguration::default() }; + let dirname = if let Some(path) = &opt.global.dirname { + path.to_path_buf() + } else if let Some(path) = &input.dirname { + expand_tilde(path) + } else { + proj_dirs.data_dir().to_path_buf() + }; + Ok(Self { - dirname: if let Some(path) = &opt.global.dirname { - path.to_path_buf() - } else if let Some(path) = &input.dirname { - expand_tilde(path) - } else { - proj_dirs.data_dir().to_path_buf() - }, + dirname: dirname.clone(), editor: if let Some(name) = &opt.global.editor { name.to_string() } else if let Some(name) = &input.editor { @@ -89,6 +97,13 @@ impl Configuration { } else { "/usr/bin/editor".to_string() }, + entries: if let Some(entries) = &opt.global.entries { + dirname.join(entries) + } else if let Some(entries) = &input.entries { + dirname.join(entries) + } else { + dirname.join("entries") + }, }) } |