2024-04-16 20:06:12 +00:00
|
|
|
use clap::{Parser, Subcommand};
|
2024-04-22 19:25:29 +00:00
|
|
|
use std::{fs, io, path::PathBuf};
|
2024-04-18 16:47:06 +00:00
|
|
|
|
2024-04-22 09:44:26 +00:00
|
|
|
use crate::{
|
2024-04-22 19:25:29 +00:00
|
|
|
commands::add_entry::add_entry,
|
2024-04-22 09:44:26 +00:00
|
|
|
commands::list_entries::list_entries,
|
|
|
|
md::{Doc, ToMd},
|
|
|
|
};
|
2024-04-16 20:06:12 +00:00
|
|
|
|
2024-04-20 18:11:04 +00:00
|
|
|
mod commands;
|
|
|
|
mod md;
|
|
|
|
mod utils;
|
|
|
|
|
2024-04-16 20:06:12 +00:00
|
|
|
#[derive(Debug, Parser)]
|
|
|
|
struct Cli {
|
|
|
|
#[arg(env)]
|
|
|
|
s10e_jrnl_file_loc: PathBuf,
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Option<Command>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
enum Command {
|
2024-04-20 18:07:07 +00:00
|
|
|
#[command(aliases = ["l", "ls", "list"])]
|
|
|
|
ListEntries,
|
2024-04-23 06:04:03 +00:00
|
|
|
#[command(aliases = ["a", "add-entry"])]
|
|
|
|
Add { title: Option<String> },
|
2024-04-16 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 19:25:29 +00:00
|
|
|
fn main() -> io::Result<()> {
|
2024-04-16 20:06:12 +00:00
|
|
|
let cli = Cli::parse();
|
2024-04-16 19:37:01 +00:00
|
|
|
println!("Hello, world!");
|
2024-04-18 16:47:06 +00:00
|
|
|
println!("cli: {cli:#?}");
|
|
|
|
|
2024-04-20 18:07:07 +00:00
|
|
|
match cli.command {
|
|
|
|
Some(Command::ListEntries) => list_entries(cli.s10e_jrnl_file_loc.clone()),
|
2024-04-22 19:25:29 +00:00
|
|
|
Some(Command::Add { title }) => add_entry(cli.s10e_jrnl_file_loc.clone(), title),
|
2024-04-20 18:07:07 +00:00
|
|
|
None => {
|
|
|
|
// TODO: handle btter
|
2024-04-22 19:25:29 +00:00
|
|
|
let file = fs::read_to_string(cli.s10e_jrnl_file_loc)?;
|
2024-04-20 18:07:07 +00:00
|
|
|
|
2024-04-22 09:44:26 +00:00
|
|
|
let doc = Doc::new(&file).unwrap();
|
2024-04-22 19:25:29 +00:00
|
|
|
println!("{}", doc.to_md());
|
|
|
|
Ok(())
|
2024-04-20 18:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|