Skip to content

Commit 6b7ecce

Browse files
committed
feat: add parser functionality to RethCli
1 parent aa95230 commit 6b7ecce

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/cli/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ homepage.workspace = true
88
repository.workspace = true
99

1010
[lints]
11+
12+
13+
[dependencies]
14+
# misc
15+
clap.workspace = true

crates/cli/cli/src/lib.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
99
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1010

11-
use std::borrow::Cow;
11+
use std::{borrow::Cow, ffi::OsString};
12+
13+
use clap::{Error, Parser};
1214

1315
/// Reth based node cli.
1416
///
@@ -22,4 +24,22 @@ pub trait RethCli: Sized {
2224

2325
/// The version of the node, such as `reth/v1.0.0`
2426
fn version(&self) -> Cow<'static, str>;
27+
28+
/// Parse args from iterator from [`std::env::args_os()`].
29+
fn parse_args() -> Result<Self, Error>
30+
where
31+
Self: Parser + Sized,
32+
{
33+
<Self as RethCli>::try_parse_from(std::env::args_os())
34+
}
35+
36+
/// Parse args from the given iterator.
37+
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
38+
where
39+
Self: Parser + Sized,
40+
I: IntoIterator<Item = T>,
41+
T: Into<OsString> + Clone,
42+
{
43+
<Self as Parser>::try_parse_from(itr)
44+
}
2545
}

0 commit comments

Comments
 (0)