feat: add parser functionality to RethCli (#9127)

This commit is contained in:
Aurélien
2024-06-26 21:39:49 +02:00
committed by GitHub
parent 818375438a
commit 9542f3bcf0
3 changed files with 29 additions and 1 deletions

View File

@ -8,3 +8,8 @@ homepage.workspace = true
repository.workspace = true
[lints]
[dependencies]
# misc
clap.workspace = true

View File

@ -8,7 +8,9 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use std::borrow::Cow;
use std::{borrow::Cow, ffi::OsString};
use clap::{Error, Parser};
/// Reth based node cli.
///
@ -22,4 +24,22 @@ pub trait RethCli: Sized {
/// The version of the node, such as `reth/v1.0.0`
fn version(&self) -> Cow<'static, str>;
/// Parse args from iterator from [`std::env::args_os()`].
fn parse_args() -> Result<Self, Error>
where
Self: Parser + Sized,
{
<Self as RethCli>::try_parse_from(std::env::args_os())
}
/// Parse args from the given iterator.
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where
Self: Parser + Sized,
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
<Self as Parser>::try_parse_from(itr)
}
}