use std::io::Read;
use anyhow::Context;
use crate::meta::{self, Harness, Scope};
#[derive(Debug, clap::Subcommand)]
pub enum MetaCommand {
Use {
harness: Harness,
#[arg(short = 's', long, default_value = "local")]
scope: Scope,
},
Hook {
harness: Harness,
},
}
pub fn run(cmd: MetaCommand) -> anyhow::Result<i32> {
match cmd {
MetaCommand::Use { harness, scope } => {
let root = std::env::current_dir().context("resolving the current directory")?;
meta::run_use(harness, scope, &root)
}
MetaCommand::Hook { harness } => match harness {
Harness::Claude => {
let mut buf = String::new();
std::io::stdin()
.read_to_string(&mut buf)
.context("reading hook input from stdin")?;
let out = meta::hook::handle_claude_hook(&buf);
if !out.is_empty() {
println!("{out}");
}
Ok(0)
}
Harness::General => {
anyhow::bail!("`general` has no hooks; there is nothing for `meta hook` to do")
}
},
}
}