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};
8use tower_lsp::{LspService, Server};
9
10use crate::{
11 cli::{Commands, ZettelSubcommand},
12 config::{Config, get_config_dir},
13 lsp::Backend,
14 types::{Group, Kasten, Priority, Task, Zettel},
15};
16
17impl Commands {
18 pub async fn process(self) -> Result<()> {
19 match self {
20 Self::Init { name } => {
21 // create the directory
22 let dir = current_dir()
23 .context("Failed to get current directory")?
24 .join(&name);
25
26 Kasten::initialize(dir.clone()).await?;
27
28 // write config that sets the filaments directory to current dir!
29 let config_str = dbg! {Config::generate(&dir)}?;
30
31 // create the config dir
32 let config_dir = get_config_dir();
33
34 create_dir_all(config_dir).expect("creating the config dir should not error");
35
36 let mut config_file = File::create(get_config_dir().join("config.ron"))
37 .context("Failed to create config file")?;
38
39 write!(config_file, "{config_str}")?;
40
41 println!("wrote config to {config_file:#?}");
42
43 // report status!
44 println!("Initialized successfully!");
45 }
46
47 Self::Zettel(zettel_sub_command) => {
48 let conf = Config::parse()?;
49 let mut kt = Kasten::instansiate(conf.fil_dir).await?;
50
51 match zettel_sub_command {
52 ZettelSubcommand::New { title } => {
53 let zettel = Zettel::new(title, &mut kt, vec![]).await?;
54 println!("Zettel Created! {zettel:#?}");
55 }
56 ZettelSubcommand::List { by_tag: _by_tag } => {}
57 }
58 }
59 Self::Lsp => {
60 let conf = Config::parse().with_context(|| "Failed to parse the config!!")?;
61 let kt = Kasten::instansiate(conf.fil_dir)
62 .await
63 .with_context(|| "Failed to initialize a kasten!!")?;
64
65 let stdin = tokio::io::stdin();
66 let stdout = tokio::io::stdout();
67
68 let (service, socket) = LspService::new(|client| Backend::new(client, kt));
69
70 Server::new(stdin, stdout, socket).serve(service).await;
71 }
72
73 Self::Todo(command) => {
74 let conf = Config::parse()?;
75 let mut kt = Kasten::instansiate(conf.fil_dir).await?;
76
77 match command {
78 super::TodoSubcommand::Group { name, parent_id } => {
79 // lets create a tag for this first group first
80 let group = Group::new(name, parent_id, &mut kt).await?;
81 println!("created group {group:#?}");
82 }
83 super::TodoSubcommand::Task { name, parent_id } => {
84 let task =
85 Task::new(name, parent_id, &mut kt, None, Priority::default()).await?;
86 println!("created task {task:#?}");
87 }
88 }
89 }
90 Self::Test => {
91 let conf = Config::parse()?;
92 let kt = Kasten::instansiate(conf.fil_dir).await?;
93 println!("kt: {kt:#?}");
94 }
95 }
96
97 Ok(())
98 }
99}