My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
1use std::{
2 env::current_dir,
3 fs::{File, create_dir_all},
4 io::Write,
5};
6
7use color_eyre::eyre::{Context, Result};
8
9use crate::{
10 cli::Commands,
11 config::{Config, get_config_dir},
12};
13
14impl Commands {
15 pub fn process(self) -> Result<()> {
16 match self {
17 Self::Init { name } => {
18 // create the directory
19 let dir = current_dir()
20 .context("Failed to get current directory")?
21 .join(&name);
22
23 // create the .filaments folder
24 let filaments_dir = dir.join(".filaments");
25
26 create_dir_all(&filaments_dir)
27 .context("Failed to create the filaments directory!")?;
28
29 // create the database inside there
30 File::create(filaments_dir.join("filaments.db"))?;
31
32 // write config that sets the filaments directory to current dir!
33 let config_kdl = dbg! {Config::generate(&dir)};
34
35 // create the config dir
36 let config_dir = get_config_dir();
37
38 create_dir_all(config_dir).expect("creating the config dir should not error");
39
40 let mut config_file = File::create(get_config_dir().join("config.kdl"))
41 .context("Failed to create config file")?;
42
43 write!(config_file, "{config_kdl}")?;
44
45 println!("wrote config to {config_file:#?}");
46
47 // report status!
48 println!("Initialized successfully!");
49 }
50 }
51
52 Ok(())
53 }
54}