feat: parsers (#9366)

This commit is contained in:
Luca Provini
2024-07-10 14:44:18 +02:00
committed by GitHub
parent f479db2010
commit 47c038201a
12 changed files with 248 additions and 16 deletions

View File

@ -8,13 +8,17 @@ homepage.workspace = true
repository.workspace = true
[lints]
workspace = true
[dependencies]
# reth
reth-cli-runner.workspace = true
reth-chainspec.workspace = true
eyre.workspace = true
# misc
clap.workspace = true
eyre.workspace = true

View File

@ -21,5 +21,5 @@ pub trait ChainSpecParser: TypedValueParser<Value = Arc<ChainSpec>> + Default {
///
/// This function will return an error if the input string cannot be parsed into a valid
/// [`ChainSpec`].
fn parse(&self, s: &str) -> eyre::Result<Arc<ChainSpec>>;
fn parse(s: &str) -> eyre::Result<Arc<ChainSpec>>;
}

View File

@ -8,12 +8,11 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use clap::{Error, Parser};
use reth_cli_runner::CliRunner;
use std::{borrow::Cow, ffi::OsString};
use reth_cli_runner::CliRunner;
use clap::{Error, Parser};
/// The chainspec module defines the different chainspecs that can be used by the node.
pub mod chainspec;
/// Reth based node cli.
@ -32,7 +31,7 @@ pub trait RethCli: Sized {
/// Parse args from iterator from [`std::env::args_os()`].
fn parse_args() -> Result<Self, Error>
where
Self: Parser + Sized,
Self: Parser,
{
<Self as RethCli>::try_parse_from(std::env::args_os())
}
@ -40,7 +39,7 @@ pub trait RethCli: Sized {
/// Parse args from the given iterator.
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where
Self: Parser + Sized,
Self: Parser,
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
@ -60,7 +59,7 @@ pub trait RethCli: Sized {
/// Parses and executes a command.
fn execute<F, R>(f: F) -> Result<R, Error>
where
Self: Parser + Sized,
Self: Parser,
F: FnOnce(Self, CliRunner) -> R,
{
let cli = Self::parse_args()?;