use anyhow::Result;
use clap::{Parser, Subcommand};
use org_core::OrgMode;
mod commands;
mod config;
use commands::{
AgendaCommand, ConfigCommand, ElementByIdCommand, HeadingCommand, ListCommand, OutlineCommand,
ReadCommand, SearchCommand,
};
use config::CliAppConfig;
#[derive(Parser)]
#[command(name = "org")]
#[command(about = "A CLI tool for org-mode functionality")]
#[command(version = env!("CARGO_PKG_VERSION"))]
struct Cli {
#[arg(short, long)]
config: Option<String>,
#[arg(short, long)]
root_directory: Option<String>,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Agenda(AgendaCommand),
Config(ConfigCommand),
List(ListCommand),
Read(ReadCommand),
Outline(OutlineCommand),
Heading(HeadingCommand),
ElementById(ElementByIdCommand),
Search(SearchCommand),
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Config(cmd) => cmd.execute(cli.config),
_ => {
let config = CliAppConfig::load(
cli.config,
cli.root_directory,
None, )?;
let org_mode = OrgMode::new(config.org)?;
match cli.command {
Commands::Agenda(cmd) => cmd.execute(org_mode, config.cli),
Commands::Config(_) => unreachable!(),
Commands::List(cmd) => cmd.execute(org_mode, config.cli),
Commands::Read(cmd) => cmd.execute(org_mode, config.cli),
Commands::Outline(cmd) => cmd.execute(org_mode, config.cli),
Commands::Heading(cmd) => cmd.execute(org_mode, config.cli),
Commands::ElementById(cmd) => cmd.execute(org_mode, config.cli),
Commands::Search(cmd) => cmd.execute(org_mode, config.cli),
}
}
}
}