Something went wrong. Try again.
My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798use std::{ env::current_dir, fs::{File, create_dir_all}, io::Write,};
use color_eyre::eyre::{Context, Result};use fil_core::{Group, Kasten, Priority, Task, Zettel};use tower_lsp::{LspService, Server};
use crate::{ cli::{Commands, ZettelSubcommand}, config::{Config, get_config_dir}, lsp::Backend,};
impl Commands { pub async fn process(self) -> Result<()> { match self { Self::Init { name } => { let dir = current_dir() .context("Failed to get current directory")? .join(&name);
Kasten::initialize(dir.clone()).await?;
// Write config that sets the filaments directory to current Dir! let config_str = dbg! {Config::generate(&dir)}?;
// create the config Dir let config_dir = get_config_dir();
create_dir_all(config_dir).expect("creating the config dir should not error");
let mut config_file = File::create(get_config_dir().join("config.ron")) .context("Failed to create config file")?;
write!(config_file, "{config_str}")?;
println!("wrote config to {config_file:#?}");
println!("Initialized successfully!"); }
Self::Zettel(zettel_sub_command) => { let conf = Config::parse()?; let mut kt = Kasten::instansiate(conf.fil_dir).await?;
match zettel_sub_command { ZettelSubcommand::New { title } => { let zettel = Zettel::new(title, &mut kt, vec![]).await?; println!("Zettel Created! {zettel:#?}"); } ZettelSubcommand::List { by_tag: _by_tag } => { unimplemented!() } } }
Self::Lsp => { // parse a Kasten let conf = Config::parse().with_context(|| "Failed to parse the config!!")?; let kt = Kasten::instansiate(conf.fil_dir) .await .with_context(|| "Failed to initialize a kasten!!")?;
// get the in and out let stdin = tokio::io::stdin(); let stdout = tokio::io::stdout();
// start the LSP let (service, socket) = LspService::new(|client| Backend::new(client, kt)); Server::new(stdin, stdout, socket).serve(service).await; }
Self::Todo(command) => { let conf = Config::parse()?; let mut kt = Kasten::instansiate(conf.fil_dir).await?;
match command { super::TodoSubcommand::Group { name, parent_id } => { let group = Group::new(name, parent_id, &mut kt).await?; println!("created group {group:#?}"); } super::TodoSubcommand::Task { name, parent_id } => { //TODO: need to expose the due date and priority through the CLI let task = Task::new(name, parent_id, &mut kt, None, Priority::default()).await?; println!("created task {task:#?}"); } } } }
Ok(()) }}