use clap::{Parser, Subcommand}; use std::{fs, io, path::PathBuf}; use crate::{ commands::add_entry::add_entry, commands::list_entries::list_entries, md::{Doc, ToMd}, }; mod commands; mod md; mod utils; #[derive(Debug, Parser)] struct Cli { #[arg(env)] s10e_jrnl_file_loc: PathBuf, #[command(subcommand)] command: Option, } #[derive(Debug, Subcommand)] enum Command { #[command(aliases = ["l", "ls", "list"])] ListEntries, #[command(aliases = ["a", "add-entry"])] Add { title: Option }, } 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 { 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)?; let doc = Doc::new(&file).unwrap(); println!("{}", doc.to_md()); Ok(()) } } }