use std::env;
use std::io::{self, Read};
use std::path::PathBuf;
use std::process::exit;
use balls::chore;
use balls::chore_cli::Cli;
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.first().map(String::as_str) == Some("protocol") {
println!("{}", chore::PROTOCOL_JSON);
return;
}
if let Err(e) = run(&args) {
eprintln!("bl-chore: {e}");
exit(1);
}
}
fn run(args: &[String]) -> io::Result<()> {
let op = args.first().ok_or_else(|| io::Error::other("usage: bl-chore <op> <phase>"))?;
let phase = args.get(1).ok_or_else(|| io::Error::other("usage: bl-chore <op> <phase>"))?;
let mut stdin = String::new();
io::stdin().read_to_string(&mut stdin)?;
let plugin = env::var("BALLS_PLUGIN_NAME").unwrap_or_else(|_| "bl-chore".to_string());
let bl = Cli::at(PathBuf::from("bl"));
chore::run(op, phase, &plugin, &stdin, &bl)
}