use amaru::{
observability::{Color, setup_observability},
panic::panic_handler,
};
use clap::{Parser, Subcommand};
use tracing::info;
mod cmd;
#[derive(Debug, Subcommand)]
enum Command {
Sync(cmd::sync::Args),
#[cfg(feature = "mithril")]
Mithril(cmd::mithril::Args),
}
#[derive(Debug, Parser)]
#[clap(name = "Amaru Ledger")]
#[clap(bin_name = "amaru-ledger")]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Command,
#[clap(long, action, env("AMARU_WITH_OPEN_TELEMETRY"))]
with_open_telemetry: bool,
#[clap(long, action, env("AMARU_WITH_JSON_TRACES"))]
with_json_traces: bool,
#[clap(long, action, env("AMARU_COLOR"))]
color: Option<Color>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
panic_handler();
let args = Cli::parse();
info!(
with_open_telemetry = args.with_open_telemetry,
with_json_traces = args.with_json_traces,
"Started with global arguments"
);
let (_metrics, teardown) =
setup_observability(args.with_open_telemetry, args.with_json_traces, Color::is_enabled(args.color));
let result = match args.command {
Command::Sync(args) => cmd::sync::run(args).await,
#[cfg(feature = "mithril")]
Command::Mithril(args) => cmd::mithril::run(args).await,
};
if let Err(report) = teardown() {
eprintln!("Failed to teardown tracing: {report}");
}
result
}