Skip to content

Commit

Permalink
feat: add parser functionality to RethCli (paradigmxyz#9127)
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Jun 26, 2024
1 parent 8183754 commit 9542f3b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

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

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

[lints]


[dependencies]
# misc
clap.workspace = true
22 changes: 21 additions & 1 deletion crates/cli/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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)
}
}

0 comments on commit 9542f3b

Please sign in to comment.