use anyhow::Result;
use clap::{Parser, Subcommand};
use org_core::{Config, OrgMode};
mod commands;
use commands::{
ConfigCommand, ElementByIdCommand, HeadingCommand, InitCommand, ListCommand, OutlineCommand,
ReadCommand, SearchCommand,
};
#[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 {
Config(ConfigCommand),
List(ListCommand),
Init(InitCommand),
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 = Config::load_with_overrides(
cli.config,
cli.root_directory,
None, )?;
let org_mode = OrgMode::new(config)?;
match cli.command {
Commands::Config(_) => unreachable!(),
Commands::List(cmd) => cmd.execute(org_mode),
Commands::Init(cmd) => cmd.execute(org_mode),
Commands::Read(cmd) => cmd.execute(org_mode),
Commands::Outline(cmd) => cmd.execute(org_mode),
Commands::Heading(cmd) => cmd.execute(org_mode),
Commands::ElementById(cmd) => cmd.execute(org_mode),
Commands::Search(cmd) => cmd.execute(org_mode),
}
}
}
}