Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parser functionality to RethCli #9127

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading