1use crate::commands::doctor::{run_doctor, run_stats, DoctorArgs, StatsArgs};
2use crate::commands::index::{run_index, run_rebuild, IndexArgs, RebuildArgs};
3use crate::commands::pins::{run_pin, run_pins, run_unpin, PinArgs, PinsArgs, UnpinArgs};
4use crate::commands::recent::{run_day, run_recent, DayArgs, RecentArgs};
5use crate::commands::search::{run_bundle, run_search, run_show, BundleArgs, SearchArgs, ShowArgs};
6use crate::commands::watch::{run_status, run_watch, StatusArgs, WatchArgs};
7use anyhow::Result;
8use clap::{CommandFactory, Parser, Subcommand};
9
10#[derive(Debug, Parser)]
11#[command(
12 version,
13 about = "Local search and recall for Codex session JSONL archives"
14)]
15struct Cli {
16 #[command(subcommand)]
17 command: Option<Command>,
18}
19
20#[derive(Debug, Subcommand)]
21enum Command {
22 Index(IndexArgs),
24 Rebuild(RebuildArgs),
26 Watch(WatchArgs),
28 Status(StatusArgs),
30 Search(SearchArgs),
32 Recent(RecentArgs),
34 Day(DayArgs),
36 Bundle(BundleArgs),
38 Show(ShowArgs),
40 Pin(PinArgs),
42 Pins(PinsArgs),
44 Unpin(UnpinArgs),
46 Doctor(DoctorArgs),
48 Stats(StatsArgs),
50}
51
52pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
53 let cli = Cli::parse_from(std::iter::once("codex-recall".to_owned()).chain(args));
54 match cli.command {
55 Some(Command::Index(args)) => run_index(args),
56 Some(Command::Rebuild(args)) => run_rebuild(args),
57 Some(Command::Watch(args)) => run_watch(args),
58 Some(Command::Status(args)) => run_status(args),
59 Some(Command::Search(args)) => run_search(args),
60 Some(Command::Recent(args)) => run_recent(args),
61 Some(Command::Day(args)) => run_day(args),
62 Some(Command::Bundle(args)) => run_bundle(args),
63 Some(Command::Show(args)) => run_show(args),
64 Some(Command::Pin(args)) => run_pin(args),
65 Some(Command::Pins(args)) => run_pins(args),
66 Some(Command::Unpin(args)) => run_unpin(args),
67 Some(Command::Doctor(args)) => run_doctor(args),
68 Some(Command::Stats(args)) => run_stats(args),
69 None => {
70 Cli::command().print_help()?;
71 println!();
72 Ok(())
73 }
74 }
75}