reth_cli_commands/
config_cmd.rs

1//! CLI command to show configs.
2
3use clap::Parser;
4use eyre::{bail, WrapErr};
5use reth_config::Config;
6use std::path::PathBuf;
7/// `reth config` command
8#[derive(Debug, Parser)]
9pub struct Command {
10    /// The path to the configuration file to use.
11    #[arg(long, value_name = "FILE", verbatim_doc_comment)]
12    config: Option<PathBuf>,
13
14    /// Show the default config
15    #[arg(long, verbatim_doc_comment, conflicts_with = "config")]
16    default: bool,
17}
18
19impl Command {
20    /// Execute `config` command
21    pub async fn execute(&self) -> eyre::Result<()> {
22        let config = if self.default {
23            Config::default()
24        } else {
25            let path = self.config.clone().unwrap_or_default();
26            // Check if the file exists
27            if !path.exists() {
28                bail!("Config file does not exist: {}", path.display());
29            }
30            // Read the configuration file
31            Config::from_path(&path)
32                .wrap_err_with(|| format!("Could not load config file: {}", path.display()))?
33        };
34        println!("{}", toml::to_string_pretty(&config)?);
35        Ok(())
36    }
37}