use bot_cli::config::BotConfig;
use schemars::schema_for;
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let schema = schema_for!(BotConfig);
let json = serde_json::to_string_pretty(&schema).unwrap();
let args: Vec<String> = env::args().collect();
let should_copy = args.iter().any(|a| a == "--copy");
if should_copy {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let crate_root = PathBuf::from(&manifest_dir);
let bot_api_schema_path =
crate_root.join("../../../bot_api/src/schemas/bot-config.schema.json");
let bot_schema_path = crate_root.join("../../schemas/bot-config.schema.json");
println!("{}", json);
if let Some(parent) = bot_api_schema_path.parent() {
fs::create_dir_all(parent).ok();
}
match fs::write(&bot_api_schema_path, &json) {
Ok(_) => eprintln!("✓ Copied schema to: {}", bot_api_schema_path.display()),
Err(e) => eprintln!("✗ Failed to write to bot_api: {}", e),
}
if let Some(parent) = bot_schema_path.parent() {
fs::create_dir_all(parent).ok();
}
match fs::write(&bot_schema_path, &json) {
Ok(_) => eprintln!("✓ Copied schema to: {}", bot_schema_path.display()),
Err(e) => eprintln!("✗ Failed to write to bot/schemas: {}", e),
}
} else {
println!("{}", json);
eprintln!("\nTip: Use --copy to automatically copy to bot_api/src/schemas/");
}
}