reth_cli_commands/
config_cmd.rs

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