1use std::path::PathBuf;
2
3#[derive(Clone, Debug)]
4pub struct Config {
5 pub directory: PathBuf,
6 pub date_pattern: String,
7 pub output_file_prefix: String,
8 pub db_path: PathBuf,
9}
10
11impl Default for Config {
12 fn default() -> Self {
13 Self {
14 directory: PathBuf::from("."),
15 date_pattern: String::from(r"^(\d{4}-\d{2}-\d{2})(\.md)?$"),
16 db_path: PathBuf::from("rusty-diary.db"),
17 output_file_prefix: String::from("rusty-diary-log"),
18 }
19 }
20}
21
22impl Config {
23 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn with_directory<P: Into<PathBuf>>(mut self, path: P) -> Self {
28 self.directory = path.into();
29 self
30 }
31
32 pub fn with_db<P: Into<PathBuf>>(mut self, path: P) -> Self {
33 self.db_path = path.into();
34 self
35 }
36
37 pub fn with_date_pattern(mut self, pattern: &str) -> Self {
38 self.date_pattern = pattern.to_string();
39 self
40 }
41
42 pub fn with_output_file_prefix(mut self, name: &str) -> Self {
43 self.output_file_prefix = name.to_string();
44 self
45 }
46}