reth_cli_commands/stage/
mod.rs1use std::sync::Arc;
4
5use crate::common::{CliNodeComponents, CliNodeTypes};
6use clap::{Parser, Subcommand};
7use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
8use reth_cli::chainspec::ChainSpecParser;
9use reth_cli_runner::CliContext;
10
11pub mod drop;
12pub mod dump;
13pub mod run;
14pub mod unwind;
15
16#[derive(Debug, Parser)]
18pub struct Command<C: ChainSpecParser> {
19 #[command(subcommand)]
20 command: Subcommands<C>,
21}
22
23#[derive(Subcommand, Debug)]
25pub enum Subcommands<C: ChainSpecParser> {
26 Run(Box<run::Command<C>>),
33 Drop(drop::Command<C>),
35 Dump(dump::Command<C>),
37 Unwind(unwind::Command<C>),
39}
40
41impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>> Command<C> {
42 pub async fn execute<N, Comp>(
44 self,
45 ctx: CliContext,
46 components: impl FnOnce(Arc<C::ChainSpec>) -> Comp,
47 ) -> eyre::Result<()>
48 where
49 N: CliNodeTypes<ChainSpec = C::ChainSpec>,
50 Comp: CliNodeComponents<N>,
51 {
52 match self.command {
53 Subcommands::Run(command) => command.execute::<N, _, _>(ctx, components).await,
54 Subcommands::Drop(command) => command.execute::<N>().await,
55 Subcommands::Dump(command) => command.execute::<N, _, _>(components).await,
56 Subcommands::Unwind(command) => command.execute::<N, _, _>(components).await,
57 }
58 }
59}
60
61impl<C: ChainSpecParser> Command<C> {
62 pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
64 match self.command {
65 Subcommands::Run(ref command) => command.chain_spec(),
66 Subcommands::Drop(ref command) => command.chain_spec(),
67 Subcommands::Dump(ref command) => command.chain_spec(),
68 Subcommands::Unwind(ref command) => command.chain_spec(),
69 }
70 }
71}