nix-configs/programs/jrnl/src/main.rs

46 lines
959 B
Rust
Raw Normal View History

#![feature(iter_collect_into)]
2024-04-16 20:06:12 +00:00
use clap::{Parser, Subcommand};
use std::{fs, path::PathBuf};
2024-04-22 09:44:26 +00:00
use crate::{
commands::list_entries::list_entries,
md::{Doc, ToMd},
};
2024-04-16 20:06:12 +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-16 20:06:12 +00:00
Add,
}
2024-04-16 19:37:01 +00:00
fn main() {
2024-04-16 20:06:12 +00:00
let cli = Cli::parse();
2024-04-16 19:37:01 +00:00
println!("Hello, world!");
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()),
Some(Command::Add) => todo!(),
None => {
// TODO: handle btter
let file = fs::read_to_string(cli.s10e_jrnl_file_loc).unwrap();
2024-04-22 09:44:26 +00:00
let doc = Doc::new(&file).unwrap();
println!("{}", doc.to_md())
2024-04-20 18:07:07 +00:00
}
}
}