diff --git a/Cargo.lock b/Cargo.lock index 2a9fc0a7fab7..b580a68e6871 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6579,6 +6579,7 @@ name = "reth-cli" version = "1.0.0" dependencies = [ "clap", + "reth-cli-runner", ] [[package]] diff --git a/crates/cli/cli/Cargo.toml b/crates/cli/cli/Cargo.toml index effd1ed29962..c2aa22e70e71 100644 --- a/crates/cli/cli/Cargo.toml +++ b/crates/cli/cli/Cargo.toml @@ -11,5 +11,8 @@ repository.workspace = true [dependencies] +# reth +reth-cli-runner.workspace = true + # misc clap.workspace = true diff --git a/crates/cli/cli/src/lib.rs b/crates/cli/cli/src/lib.rs index 5e273d88717f..ccaa900edbd7 100644 --- a/crates/cli/cli/src/lib.rs +++ b/crates/cli/cli/src/lib.rs @@ -10,6 +10,8 @@ use std::{borrow::Cow, ffi::OsString}; +use reth_cli_runner::CliRunner; + use clap::{Error, Parser}; /// Reth based node cli. @@ -42,4 +44,25 @@ pub trait RethCli: Sized { { ::try_parse_from(itr) } + + /// Executes a command. + fn with_runner(self, f: F) -> R + where + F: FnOnce(Self, CliRunner) -> R, + { + let runner = CliRunner::default(); + + f(self, runner) + } + + /// Parses and executes a command. + fn execute(f: F) -> Result + where + Self: Parser + Sized, + F: FnOnce(Self, CliRunner) -> R, + { + let cli = Self::parse_args()?; + + Ok(cli.with_runner(f)) + } }