mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add parser functionality to RethCli (#9127)
This commit is contained in:
@ -8,3 +8,8 @@ homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
|
||||
|
||||
[dependencies]
|
||||
# misc
|
||||
clap.workspace = true
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user