jrnl: adding entries now works!!

This commit is contained in:
Schrottkatze 2024-04-22 21:25:29 +02:00
parent b967f6e90e
commit aaec1f1f78
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
5 changed files with 89 additions and 13 deletions

View file

@ -1,8 +1,9 @@
#![feature(iter_collect_into)]
use clap::{Parser, Subcommand};
use std::{fs, path::PathBuf};
use std::{fs, io, path::PathBuf};
use crate::{
commands::add_entry::add_entry,
commands::list_entries::list_entries,
md::{Doc, ToMd},
};
@ -23,23 +24,26 @@ struct Cli {
enum Command {
#[command(aliases = ["l", "ls", "list"])]
ListEntries,
Add,
Add {
title: Option<String>,
},
}
fn main() {
fn main() -> io::Result<()> {
let cli = Cli::parse();
println!("Hello, world!");
println!("cli: {cli:#?}");
match cli.command {
Some(Command::ListEntries) => list_entries(cli.s10e_jrnl_file_loc.clone()),
Some(Command::Add) => todo!(),
Some(Command::Add { title }) => add_entry(cli.s10e_jrnl_file_loc.clone(), title),
None => {
// TODO: handle btter
let file = fs::read_to_string(cli.s10e_jrnl_file_loc).unwrap();
let file = fs::read_to_string(cli.s10e_jrnl_file_loc)?;
let doc = Doc::new(&file).unwrap();
println!("{}", doc.to_md())
println!("{}", doc.to_md());
Ok(())
}
}
}