1use amareleo_chain_cli::{commands::CLI, helpers::Updater};
17
18use clap::Parser;
19use std::{env, process::exit};
20
21#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
22use tikv_jemallocator::Jemalloc;
23
24#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
25#[global_allocator]
26static GLOBAL: Jemalloc = Jemalloc;
27
28pub struct BuildInfo<'a> {
29 pub bin: &'a str,
30 pub version: &'a str,
31 pub repo: &'a str,
32 pub branch: &'a str,
33 pub commit: &'a str,
34 pub features: &'a str,
35}
36
37pub fn main_core(build: &BuildInfo) -> anyhow::Result<()> {
38 check_for_version(build);
40
41 let cli = CLI::parse();
43 println!("{}", Updater::print_cli(build.repo, build.bin));
45 match cli.command.parse(build.repo, build.bin) {
47 Ok(output) => println!("{output}\n"),
48 Err(error) => {
49 println!("⚠️ {error}");
51 for entry in error.chain().skip(1) {
52 println!(" ↳ {entry}");
53 }
54 println!();
55 exit(1);
56 }
57 }
58 Ok(())
59}
60
61fn check_for_version(build: &BuildInfo) {
63 if let Some(first_arg) = env::args().nth(1) {
64 if ["--version", "-V"].contains(&&*first_arg) {
65 println!("{} {} {} {} features=[{}]", build.bin, build.version, build.branch, build.commit, build.features);
66 exit(0);
67 }
68 }
69}