1#![doc(
4 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
5 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
6 issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
7)]
8#![cfg_attr(not(test), warn(unused_crate_dependencies))]
9#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
10
11use clap::{Error, Parser};
12use reth_cli_runner::CliRunner;
13use reth_db::ClientVersion;
14use std::{borrow::Cow, ffi::OsString};
15
16pub mod chainspec;
18use crate::chainspec::ChainSpecParser;
19
20pub trait RethCli: Sized {
27 type ChainSpecParser: ChainSpecParser;
29
30 fn name(&self) -> Cow<'static, str>;
32
33 fn version(&self) -> Cow<'static, str>;
35
36 fn parse_args() -> Result<Self, Error>
38 where
39 Self: Parser,
40 {
41 <Self as RethCli>::try_parse_from(std::env::args_os())
42 }
43
44 fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
46 where
47 Self: Parser,
48 I: IntoIterator<Item = T>,
49 T: Into<OsString> + Clone,
50 {
51 <Self as Parser>::try_parse_from(itr)
52 }
53
54 fn with_runner<F, R>(self, f: F, runner: CliRunner) -> R
56 where
57 F: FnOnce(Self, CliRunner) -> R,
58 {
59 f(self, runner)
60 }
61
62 fn execute<F, R>(f: F) -> Result<R, Error>
64 where
65 Self: Parser,
66 F: FnOnce(Self, CliRunner) -> R,
67 {
68 let cli = Self::parse_args()?;
69 let runner = CliRunner::try_default_runtime()?;
70 Ok(cli.with_runner(f, runner))
71 }
72
73 fn client_version() -> ClientVersion;
75}