use clap::{Parser, Subcommand};
use tracing::error;
use crate::common::LogArgs;
#[derive(Parser, Debug)]
#[command(name = "mega-evme", infer_subcommands = true, version = "0.1")]
pub struct MainCmd {
#[command(flatten)]
pub log: LogArgs,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum Commands {
Run(crate::run::Cmd),
Tx(crate::tx::Cmd),
Replay(crate::replay::Cmd),
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Custom error: {0}")]
Custom(&'static str),
#[error("{0}")]
Evme(#[from] crate::common::EvmeError),
}
impl MainCmd {
pub async fn run(self) -> Result<(), Error> {
self.log.init();
match self.command {
Commands::Run(cmd) => {
cmd.run().await?;
Ok(())
}
Commands::Tx(cmd) => {
cmd.run().await?;
Ok(())
}
Commands::Replay(cmd) => {
cmd.run().await?;
Ok(())
}
}
.inspect_err(|e| {
error!(err = ?e, "Error executing command");
eprintln!("{e}");
std::process::exit(1);
})
}
}