mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate CLI runner in CLI trait (#9146)
This commit is contained in:
@ -11,5 +11,8 @@ repository.workspace = true
|
||||
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-cli-runner.workspace = true
|
||||
|
||||
# misc
|
||||
clap.workspace = true
|
||||
|
||||
@ -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 {
|
||||
{
|
||||
<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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user