Skip to content

Commit

Permalink
feat: integrate CLI runner in CLI trait (#9146)
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Jun 27, 2024
1 parent 26b79f8 commit c23fe39
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/cli/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ repository.workspace = true


[dependencies]
# reth
reth-cli-runner.workspace = true

# misc
clap.workspace = true
23 changes: 23 additions & 0 deletions crates/cli/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use std::{borrow::Cow, ffi::OsString};

use reth_cli_runner::CliRunner;

use clap::{Error, Parser};

/// Reth based node cli.
Expand Down Expand Up @@ -42,4 +44,25 @@ pub trait RethCli: Sized {
{
<Self as Parser>::try_parse_from(itr)
}

/// Executes a command.
fn with_runner<F, R>(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, R>(f: F) -> Result<R, Error>
where
Self: Parser + Sized,
F: FnOnce(Self, CliRunner) -> R,
{
let cli = Self::parse_args()?;

Ok(cli.with_runner(f))
}
}

0 comments on commit c23fe39

Please sign in to comment.