use color_eyre::Result;
use clap::Parser;
use tnj_tui::{Config, Database, Profile, cli::{Cli, Commands}};
fn main() -> Result<()> {
color_eyre::install()?;
let cli = Cli::parse();
let profile = if cli.dev {
Profile::Dev
} else {
Profile::Prod
};
let config = Config::load_with_profile(profile)?;
let db_path = config.get_database_path();
let db = Database::new(
db_path.to_str()
.ok_or_else(|| color_eyre::eyre::eyre!("Database path contains invalid UTF-8"))?
)?;
match cli.command.unwrap_or(Commands::Tui) {
Commands::Tui => {
let app = tnj_tui::tui::App::new(config, db)?;
tnj_tui::tui::run_event_loop(app)?;
}
Commands::AddTask { title, due, tags } => {
tnj_tui::cli::handle_add_task(title, due, tags, &db)?;
}
Commands::AddNote { title, content, tags } => {
tnj_tui::cli::handle_add_note(title, content, tags, &db)?;
}
Commands::AddJournal { content, title, tags } => {
tnj_tui::cli::handle_add_journal(content, title, tags, &db)?;
}
}
Ok(())
}