#[macro_use]
extern crate rust_i18n;
i18n!("locales");
use anyhow::Result;
use clap::{CommandFactory, Parser};
fn main() {
llman::init_locale();
if let Err(e) = run() {
if let Some(ce) = e.downcast_ref::<clap::Error>() {
let code = ce.exit_code();
let _ = ce.print();
std::process::exit(code);
}
let message = e
.downcast_ref::<llman::error::LlmanError>()
.map(llman::error::LlmanError::display_localized)
.unwrap_or_else(|| e.to_string());
eprintln!("{}", t!("messages.error", error = message));
std::process::exit(1);
}
}
fn run() -> Result<()> {
let raw: Vec<String> = std::env::args().collect();
let program = &raw[0];
let rest: Vec<&str> = raw[1..].iter().map(String::as_str).collect();
let argv: Vec<&str> = if rest.is_empty() {
vec![program.as_str(), "sdd", "--help"]
} else {
std::iter::once(program.as_str())
.chain(std::iter::once("sdd"))
.chain(rest.iter().copied())
.collect()
};
let cli = llman::cli::Cli::try_parse_from(&argv)?;
match cli.command {
Some(llman::cli::Commands::Sdd(sdd_args)) => llman::sdd::command::run(&sdd_args),
_ => {
let mut cmd = llman::cli::Cli::command();
cmd.print_help()?;
Ok(())
}
}
}