mod agents;
mod engine;
mod install;
mod os;
mod procs;
mod shells;
mod store;
mod terminals;
mod tui;
use std::process::ExitCode;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "kaeru", version, about)]
struct Cli {
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Subcommand)]
enum Command {
List,
Install,
Uninstall,
Doctor,
Options,
Init {
#[arg(value_enum)]
shell: shells::Shell,
},
#[command(hide = true)]
Shell {
#[command(subcommand)]
event: ShellEvent,
},
Resume {
#[arg(long, value_enum, hide = true)]
shell: Option<shells::Shell>,
},
#[command(hide = true)]
Hook {
#[arg(value_enum)]
agent: agents::Agent,
},
}
#[derive(Subcommand)]
enum ShellEvent {
Start {
#[arg(long)]
pid: u32,
#[arg(long)]
parent: Option<u32>,
},
}
fn main() -> ExitCode {
match run(Cli::parse()) {
Ok(code) => code,
Err(error) => {
eprintln!("kaeru: {error:#}");
ExitCode::FAILURE
}
}
}
fn run(cli: Cli) -> Result<ExitCode> {
match cli.command {
None => tui::pick(),
Some(Command::List) => tui::list().map(|()| ExitCode::SUCCESS),
Some(Command::Install) => install::install().map(|()| ExitCode::SUCCESS),
Some(Command::Uninstall) => install::uninstall().map(|()| ExitCode::SUCCESS),
Some(Command::Doctor) => install::doctor(),
Some(Command::Options) => tui::options().map(|()| ExitCode::SUCCESS),
Some(Command::Resume { shell }) => tui::resume(shell),
Some(Command::Init { shell }) => shells::print_init(shell).map(|()| ExitCode::SUCCESS),
Some(Command::Shell {
event: ShellEvent::Start { pid, parent },
}) => Ok(shells::start(pid, parent)),
Some(Command::Hook { agent }) => agents::run_hook(agent).map(|()| ExitCode::SUCCESS),
}
}