feat: add reth config cmd to dump default reth.toml (#2167)

This commit is contained in:
georgewhewell
2023-04-10 18:09:23 +02:00
committed by GitHub
parent a83de80afa
commit d0da2a3e92
5 changed files with 46 additions and 1 deletions

View File

@ -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"

View File

@ -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)]

38
bin/reth/src/config.rs Normal file
View File

@ -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<PlatformPath<ConfigPath>>,
/// 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::<Config>(path.as_ref()).wrap_err_with(|| {
format!("Could not load config file: {}", path.as_ref().display())
})?
};
println!("{}", toml::to_string_pretty(&config)?);
Ok(())
}
}

View File

@ -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;