diff --git a/Cargo.lock b/Cargo.lock index c9dce1f6fa..354c4acdbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4486,6 +4486,7 @@ dependencies = [ "tempfile", "thiserror", "tokio", + "toml 0.7.3", "tracing", "tui", ] diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 49f5cbc5e5..1bd98580a7 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -51,6 +51,7 @@ serde_json = "1.0" shellexpand = "3.0.0" dirs-next = "2.0.0" confy = "0.5" +toml = {version = "0.7", features = ["display"]} # metrics metrics = "0.20.1" diff --git a/bin/reth/src/cli.rs b/bin/reth/src/cli.rs index ed49726b5a..6f691de183 100644 --- a/bin/reth/src/cli.rs +++ b/bin/reth/src/cli.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use crate::{ - chain, db, + chain, config, db, dirs::{LogsDir, PlatformPath}, drop_stage, dump_stage, node, p2p, runner::CliRunner, @@ -35,6 +35,7 @@ pub fn run() -> eyre::Result<()> { Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()), Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), Commands::TestEthChain(command) => runner.run_until_ctrl_c(command.execute()), + Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), } } @@ -76,6 +77,9 @@ pub enum Commands { /// Generate Test Vectors #[command(name = "test-vectors")] TestVectors(test_vectors::Command), + /// Write config to stdout + #[command(name = "config")] + Config(config::Command), } #[derive(Debug, Parser)] diff --git a/bin/reth/src/config.rs b/bin/reth/src/config.rs new file mode 100644 index 0000000000..766186eab0 --- /dev/null +++ b/bin/reth/src/config.rs @@ -0,0 +1,38 @@ +//! CLI command to show configs +use clap::Parser; +use eyre::{bail, WrapErr}; +use reth_staged_sync::Config; + +use crate::dirs::{ConfigPath, PlatformPath}; + +/// `reth config` command +#[derive(Debug, Parser)] +pub struct Command { + /// The path to the configuration file to use. + #[arg(long, value_name = "FILE", verbatim_doc_comment)] + config: Option>, + + /// Show the default config + #[arg(long, verbatim_doc_comment, conflicts_with = "config")] + default: bool, +} + +impl Command { + /// Execute `config` command + pub async fn execute(&self) -> eyre::Result<()> { + let config = if self.default { + Config::default() + } else { + let path = self.config.clone().unwrap_or_default(); + // confy will create the file if it doesn't exist; we don't want this + if !path.as_ref().exists() { + bail!("Config file does not exist: {}", path.as_ref().display()); + } + confy::load_path::(path.as_ref()).wrap_err_with(|| { + format!("Could not load config file: {}", path.as_ref().display()) + })? + }; + println!("{}", toml::to_string_pretty(&config)?); + Ok(()) + } +} diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 708a50c54b..44a1cedff2 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -10,6 +10,7 @@ pub mod args; pub mod chain; pub mod cli; +pub mod config; pub mod db; pub mod dirs; pub mod drop_stage;