#![recursion_limit = "256"]
use clap::{Parser, Subcommand};
use miden_node_utils::logging::OpenTelemetry;
mod commands;
#[cfg(test)]
mod tests;
#[derive(Parser)]
#[command(version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand)]
pub enum Command {
#[command(subcommand)]
Store(commands::store::StoreCommand),
#[command(subcommand)]
Rpc(commands::rpc::RpcCommand),
#[command(subcommand)]
BlockProducer(commands::block_producer::BlockProducerCommand),
#[command(subcommand)]
Validator(commands::validator::ValidatorCommand),
#[command(subcommand)]
Bundled(Box<commands::bundled::BundledCommand>),
}
impl Command {
fn open_telemetry(&self) -> OpenTelemetry {
if match self {
Command::Store(subcommand) => subcommand.is_open_telemetry_enabled(),
Command::Rpc(subcommand) => subcommand.is_open_telemetry_enabled(),
Command::BlockProducer(subcommand) => subcommand.is_open_telemetry_enabled(),
Command::Validator(subcommand) => subcommand.is_open_telemetry_enabled(),
Command::Bundled(subcommand) => subcommand.is_open_telemetry_enabled(),
} {
OpenTelemetry::Enabled
} else {
OpenTelemetry::Disabled
}
}
async fn execute(self) -> anyhow::Result<()> {
match self {
Command::Rpc(rpc_command) => rpc_command.handle().await,
Command::Store(store_command) => store_command.handle().await,
Command::BlockProducer(block_producer_command) => block_producer_command.handle().await,
Command::Validator(validator) => validator.handle().await,
Command::Bundled(node) => node.handle().await,
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let _otel_guard = miden_node_utils::logging::setup_tracing(cli.command.open_telemetry())?;
cli.command.execute().await
}