1use clap::{Parser, Subcommand};
2use tracing::error;
3
4use crate::common::LogArgs;
5
6#[derive(Parser, Debug)]
8#[command(name = "mega-evme", infer_subcommands = true, version = "0.1")]
9pub struct MainCmd {
10 #[command(flatten)]
12 pub log: LogArgs,
13
14 #[command(subcommand)]
16 pub command: Commands,
17}
18
19#[derive(Subcommand, Debug)]
21#[allow(clippy::large_enum_variant)]
22pub enum Commands {
23 Run(crate::run::Cmd),
25 Tx(crate::tx::Cmd),
27 Replay(crate::replay::Cmd),
29}
30
31#[derive(Debug, thiserror::Error)]
33pub enum Error {
34 #[error("Custom error: {0}")]
36 Custom(&'static str),
37 #[error("{0}")]
39 Evme(#[from] crate::common::EvmeError),
40}
41
42impl MainCmd {
43 pub async fn run(self) -> Result<(), Error> {
45 self.log.init();
47
48 match self.command {
49 Commands::Run(cmd) => {
50 cmd.run().await?;
51 Ok(())
52 }
53 Commands::Tx(cmd) => {
54 cmd.run().await?;
55 Ok(())
56 }
57 Commands::Replay(cmd) => {
58 cmd.run().await?;
59 Ok(())
60 }
61 }
62 .inspect_err(|e| {
63 error!(err = ?e, "Error executing command");
64 eprintln!("{e}");
65 std::process::exit(1);
66 })
67 }
68}