1use std::collections::HashSet;
13use std::fs;
14use std::path::PathBuf;
15
16use internet2::addr::ServiceAddr;
17
18#[derive(Clone, PartialEq, Eq, Debug, Display)]
22#[display(Debug)]
23pub struct Config {
24 pub rpc_endpoint: ServiceAddr,
26
27 pub data_dir: PathBuf,
29
30 pub databases: HashSet<String>,
31
32 pub verbose: u8,
34}
35
36impl Config {
37 pub fn process(&mut self) {
38 self.data_dir =
39 PathBuf::from(shellexpand::tilde(&self.data_dir.display().to_string()).to_string());
40
41 let me = self.clone();
42 let mut data_dir = self.data_dir.to_string_lossy().into_owned();
43 self.process_dir(&mut data_dir);
44 self.data_dir = PathBuf::from(data_dir);
45
46 fs::create_dir_all(&self.data_dir).expect("Unable to access data directory");
47
48 for dir in vec![&mut self.rpc_endpoint] {
49 if let ServiceAddr::Ipc(ref mut path) = dir {
50 me.process_dir(path);
51 }
52 }
53 }
54
55 pub fn process_dir(&self, path: &mut String) {
56 *path = path.replace("{data_dir}", &self.data_dir.to_string_lossy());
57 *path = shellexpand::tilde(path).to_string();
58 }
59}