use amareleo_chain_cli::{commands::CLI, helpers::Updater};
use clap::Parser;
use std::{env, process::exit};
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
use tikv_jemallocator::Jemalloc;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
pub struct BuildInfo<'a> {
pub bin: &'a str,
pub version: &'a str,
pub repo: &'a str,
pub branch: &'a str,
pub commit: &'a str,
pub features: &'a str,
}
pub fn main_core(build: &BuildInfo) -> anyhow::Result<()> {
check_for_version(build);
let cli = CLI::parse();
println!("{}", Updater::print_cli(build.repo, build.bin));
match cli.command.parse(build.repo, build.bin) {
Ok(output) => println!("{output}\n"),
Err(error) => {
println!("⚠️ {error}");
for entry in error.chain().skip(1) {
println!(" ↳ {entry}");
}
println!();
exit(1);
}
}
Ok(())
}
fn check_for_version(build: &BuildInfo) {
if let Some(first_arg) = env::args().nth(1) {
if ["--version", "-V"].contains(&&*first_arg) {
println!("{} {} {} {} features=[{}]", build.bin, build.version, build.branch, build.commit, build.features);
exit(0);
}
}
}