diff --git a/Cargo.lock b/Cargo.lock index 400aba307a9..cff2074fc53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6523,6 +6523,9 @@ dependencies = [ [[package]] name = "reth-cli" version = "1.0.0" +dependencies = [ + "clap", +] [[package]] name = "reth-cli-commands" diff --git a/crates/cli/cli/Cargo.toml b/crates/cli/cli/Cargo.toml index 3487782c9e2..effd1ed2996 100644 --- a/crates/cli/cli/Cargo.toml +++ b/crates/cli/cli/Cargo.toml @@ -8,3 +8,8 @@ homepage.workspace = true repository.workspace = true [lints] + + +[dependencies] +# misc +clap.workspace = true diff --git a/crates/cli/cli/src/lib.rs b/crates/cli/cli/src/lib.rs index 513380fdd05..5e273d88717 100644 --- a/crates/cli/cli/src/lib.rs +++ b/crates/cli/cli/src/lib.rs @@ -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 + where + Self: Parser + Sized, + { + ::try_parse_from(std::env::args_os()) + } + + /// Parse args from the given iterator. + fn try_parse_from(itr: I) -> Result + where + Self: Parser + Sized, + I: IntoIterator, + T: Into + Clone, + { + ::try_parse_from(itr) + } }